[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Form Validaton, Select Menus Losing Session Info

Posted on 2006-05-05
4
Medium Priority
?
162 Views
Last Modified: 2013-12-24
I have a two page processing set up, form and action page with error checking for required fields.  All fields are stored in a session but I am having sort of two problems with select menus.

First off, if a user missed a required field on the form page when they submitted to the action/processing page, select menu values that were stored in the session did not update themselves. So if a user had chosen the state of California on the form page, on the action/processing page it was back to the default 'Choose A State'. This was the case for all select menus on the page. To altered the select menus on the action page as such;

<cfselect
          name="State"          
          required="yes"
          message="Please select your State">
              <OPTION value="#session.buynow_nfo.State#" selected><cfoutput>#session.buynow_nfo.State#</cfoutput></OPTION>
              <option value="Alabama">Alabama</option>
              <option value="Alaska">Alaska</option>
              <option value="Arizona">Arizona</option>
              <option value="Arkansas">Arkansas</option>
              <option value="California">California</option>
               etc....
</cfselect>

Which worked, or so I thought.  If the user makes an error in a text field or select menu, select menus that have been selected did update with the session info passed to the action page.  However, if a user makes TWO mistakes and therefore submits the form twice all select boxes lose the session info and display the #session.buynow_nfo.NAMEOFFIELD# fix, I thought I had created.

This is not seen as an error, so when and if all the required text fields are correct the form submits and the select values all come through with #session.buynow_nfo.NAMEOFFIELD#

How can I fix this?
0
Comment
Question by:dndco
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:dgrafx
ID: 16617301
I believe you need to do something like:

<cfoutput>
<select name="State">
<cfloop list="#statelist#" index="ii">
<option value="#ii#" <cfif ii is session.buynow_nfo.State>selected</cfif>>#ii#
</cfloop>
</select>
</cfoutput>
0
 

Author Comment

by:dndco
ID: 16619273
Thanks anyway, but it looks like you are pulling the #statelist# from a DB and looping through to the next item with "ii".  I don't have a database for this.   I just have the 50 states coded in the form.  

However, your code did give me an idea.  I wrapped the selected option value with cfoutput like this;

<cfselect
          name="State"          
          required="yes"
          message="Please select your State">
              <cfoutput>
              <OPTION value="#session.buynow_nfo.State#" selected>#session.buynow_nfo.State#</OPTION>
             </cfoutput>
              <option value="Alabama">Alabama</option>
              <option value="Alaska">Alaska</option>
              <option value="Arizona">Arizona</option>
              <option value="Arkansas">Arkansas</option>
              <option value="California">California</option>
               etc....
</cfselect>

And it works perfectly now.  

0
 
LVL 25

Accepted Solution

by:
dgrafx earned 1000 total points
ID: 16619479
I did notice that you didn't have output around the value but I thought that was just a mistake when typing in this forum.
#statelist# just meant your list of states instead of tying them in.

Good luck ...
0
 

Author Comment

by:dndco
ID: 16620046
I am happy with the results, thanks.

I'll be posting a new question tomorrow.  Another problem with the same form.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month19 days, 10 hours left to enroll

873 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