• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

Coldfusion - retaining form input when refreshing

Can anyone tell me how to retain form input when refreshing.

I have a form with quite a few input boxes and so on, once the user has filled out the form and submitted, coldfusion will validate the form and bring back any missed fields or errors, this in turn wipes the form clean.

I've used "preservedata" before but im not using cfform, just a plain form tag.

So I guess im asking if there is any other way to preservedata on refresh?

thanks in advance.
  • 4
  • 3
3 Solutions
Ryan ChongCommented:
try use

#form.variable# ?

something like:

<cfparam name="form.myfield" type="string" default="" />


  <input name="myfield" type="text" id="myfield" value="#form.myfield#">
CurtinPropAuthor Commented:
thast what Im using at the moment, seems to work ok for most of the input fields how one textarea always clears on refresh.

my code for most of my input forms is as shown in snippet (similiar to above):

<!--- example for form.email --->
<cfparam name="form.email" default="">
<input type="text" id="Email" class="inputbox" name="Email" message="" validateat="onServer" value="#FORM.Email#" size="30" > 
<!--- example for form.comments --->
<cfparam name="FORM.Comments" default="">
<textarea name="Comments" id="Comments" cols="40" rows="6" wrap="hard" class="inputbox" message="Please describe your query in here" value="#FORM.Comments#"></textarea>

Open in new window

CurtinPropAuthor Commented:
The form also wipes drop downs and checkboxes, so would be ideal to cater for that data to.

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

if, as you say, you are using regular FORM instead of CFFORM, the regular html textarea field does not have a VALUE attribute. instead of using value="#form.comments#" in your textarea, put the actual value between the opening and closing tags: <textarea ...>#form.comments#</textarea>

as for checkboxes and radio buttons, the general principle is similar:
<cfparam name="form.mycheckbox" default="0">
<cfparam name="myradiogroup" defualt="no">
<input type="checkbox" name="mycheckbox" value="1" <cfif form.checkbox eq 1>checked="checked"</cfif>><label for="mycheckbox">my checkbox</label>
<input type="radio" name="myradiogroup" value="no" <cfif form.myradiogroup eq 'no'>checked="checked"</cfif>>No <input type="radio" name="myradiogroup" value="yes"<cfif form.myradiogroup eq 'yes'>checked="checked"</cfif>>Yes

oops, the second cfparam in my sample should, of course, be
<cfparam name="form.myradiogroup" defualt="no">
CurtinPropAuthor Commented:
thats spot on AZ, how about drop downs? im assuming its the same sort of process?
yep, exactly the same with regular selects:

<cfparam name="form.myselect" default="0">
<select name="myselect" size="1">
<option value="0" <cfif form.myselect eq 0>selected="selected"</cfif>>Option 0</option>
<option value="1" <cfif form.myselect eq 1>selected="selected"</cfif>>Option 1</option>

if your dropdown is populated by a query, it is just same easy:
<cfparam name="form.myselect2" default="1">
<select name="myselect2" size="1">
<cfloop query="somequery">
<option value="#somequery.valuecolumn#" <cfif form.myselect2 eq somequery.valuecolumn>selected="selected"</cfif>>#somequery.displaycolumn#</option>

with multiple-selects it is just a tad bit more complicated, since they store the selected values as a comma-delimited list:
<cfparam name="form.mymultiselect" default="1,4,5">
<select name="mymultiselect" multiple="true" size="5">
<option value="0" <cfif listfindnocase(form.mymultiselect, '0')>selected="selected"</cfif>>Option 0</option>
<option value="1" <cfif listfindnocase(form.mymultiselect, '1')>selected="selected"</cfif>>Option 1</option>
<option value="5" <cfif listfindnocase(form.mymultiselect, '5')>selected="selected"</cfif>>Option 5</option>

same approach applies to a group of checkboxes with same name but unique values - the selected values in this case are stored as a comma-delimited list in a single form variable.

CurtinPropAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now