Solved

Coldfusion - retaining form input when refreshing

Posted on 2008-10-20
8
521 Views
Last Modified: 2008-10-20
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.
0
Comment
Question by:CurtinProp
  • 4
  • 3
8 Comments
 
LVL 49

Expert Comment

by:Ryan Chong
ID: 22755882
try use

#form.variable# ?

something like:


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

then:

  <input name="myfield" type="text" id="myfield" value="#form.myfield#">
0
 
LVL 2

Author Comment

by:CurtinProp
ID: 22755912
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

0
 
LVL 2

Author Comment

by:CurtinProp
ID: 22755920
The form also wipes drop downs and checkboxes, so would be ideal to cater for that data to.

0
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 500 total points
ID: 22756108
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

hth
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 22756179
oops, the second cfparam in my sample should, of course, be
<cfparam name="form.myradiogroup" defualt="no">
0
 
LVL 2

Author Comment

by:CurtinProp
ID: 22763830
thats spot on AZ, how about drop downs? im assuming its the same sort of process?
0
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 500 total points
ID: 22763894
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>
...
</select>

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>
</cfloop>
</select>

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>
...
</select>

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.

hth
0
 
LVL 2

Author Comment

by:CurtinProp
ID: 22763941
Champion!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Enter key on html form page 11 48
coldfusion grab more the one form field to make an insert 3 29
html5 auto send email 7 22
REReplaceNoCase help 1 16
This article discusses four methods for overlaying images in a container on a web page
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now