By S. Costello


2018-10-11 14:35:28 8 Comments

My question references the following question/answer provided in this stackoverflow post: Form Variables are not showing up after form submit. ColdFusion

I wanted to comment in the above referenced post, but I don't have enough reputation points. I see the answer by Samuel Dealey above indicating that using a cflocation or location.replace() could result in Form variables not showing up. That is exactly what is happening in my scenario.

I have a simple registration form submission. Upon form submission the form data is sent to a page named addCampaign.cfm. addCampaign.cfm contains code that will write the registration data to the database. After writing the registration info to database, I verify that info was written to database. At that point I then redirect the user to a specific page if registration was successful, and if not successful then redirect back to the registration form page with an appropriate error message.

I have tried using both for the redirect, and have attempted using javascript location.replace(), both result in the same problem.

The issue I am running into is that:

1) The redirect never occurs

2) I am using to display the struct, but it lists it as empty

3) I have removed the cflocation and location.replace() and can verify that my form elements do exist in the form struct.

4) The form data is being written to the database, which is very strange, considering that the form struct is being displayed as empty.

I don't understand why the form struct is empty when the data is being written to the database, and furthermore I don't know why the redirect does not work. Can anybody provide some clarification on why this would be happening?

1 comments

@James A Mohler 2018-10-11 14:43:47

Consider this code on a single file

<cfif cgi.request_method EQ "post">
    <cfdump var="#form#">

    <!--- More importantly, DB inserts --->
</cfif>



<form method="post" action="?">
  <!--- Lots of other fields go here too --->

  <input type="submit" name="btnSubmit" id="btnSubmit" value="OK" />
</form>

If you do it this way, you don't have to worry about pushing data over redirect of some sort. You are already on the page you want. action="?" basically means submit to the same field as I am already on. Note that the file's behavior is different on a GET vs POST.

@Redtopia 2018-10-11 14:52:17

This is what I was going to recommend. Use the same page to handle the submit. Put logic to handle the form submission at the top of the page. No need for a redirect. Basic form submission pattern.

@S. Costello 2018-10-11 17:17:03

James - Thanks a bunch. That helped me out. It's been a while since I coded in ColdFusion. I am more familiar with PHP and C#, and I was obviously turning this into something more complicated than I needed to.

Related Questions

Sponsored Content

0 Answered Questions

Can I use cflocation and/or cfhttp to mimic a javascript redirect with form post?

27 Answered Questions

[SOLVED] Prevent users from submitting a form by hitting Enter

16 Answered Questions

[SOLVED] How to prevent buttons from submitting forms

22 Answered Questions

[SOLVED] php $_POST array empty upon form submission

  • 2009-08-15 21:35:05
  • Mike D
  • 124553 View
  • 73 Score
  • 22 Answer
  • Tags:   php arrays forms post

31 Answered Questions

[SOLVED] How to manage a redirect request after a jQuery Ajax call

0 Answered Questions

Coldfusion cflocation strange behavior

2 Answered Questions

[SOLVED] what happens on form submits in Coldfusion?

1 Answered Questions

0 Answered Questions

Redirection after form submit only happens upon refresh

1 Answered Questions

[SOLVED] How to fill a remote ColdFusion form using PHP?

Sponsored Content