Solved

Coldfusion - search form pre-fill

Posted on 2010-08-12
5
470 Views
Last Modified: 2013-12-24
I'm trying to get my form to remember the last search criteria that was submitted.
I've seen a couple tutorials on this but they were all for your basic text block. My form has drop down lists  and my current code doesnt throw an error but doesnt work either. Example for the minimumPrice field:

<!---prefill form--->
<cfif isDefined("Form.minimumPrice")>
<cfset CLIENT.minimumPrice = Form.minimumPrice>
<cfset prefillminimumprice = Form.minimumPrice>
<cfelseif isDefined("CLIENT.lastminimumPrice")>
<cfset prefillminimumPrice = CLIENT.lastminimumPrice>
<cfelse>
<cfset prefillminimumPrice = " ">
</cfif>
---------------------------------------
and in my form:

<select name="minimumprice">
            <option value="1" selected>#prefillminimumPrice#</option>
            <option value="10000">$10,000</option>
            <option value="25000">$25,000</option>
            <option value="50000">$50,000</option>
            <option value="75000">$75,000</option>
</select>

Any ideas on getting this to work?

Thanks!
0
Comment
Question by:Bang-O-Matic
  • 2
  • 2
5 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 33424848
just put the form  either in session variable or localScope. And then when you come back to the page do this

<cfif session.form eq form>selected</cfif>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 33425094
You need to compare the values for each <option> and if the values are the same, mark one as "selected".

<select name="minimumprice">
...
<option value="10000" <cfif YourSavedValue eq 10000>selected</cfif>>$10,000</option>
<option value="25000" <cfif YourSavedValue eq 25000>selected</cfif>>$25,000</option>
....
</select>

... OR if your list is being populated from a query, you could use a cfselect and the "selected" attribute.

<cfform>
        <cfselect name="minimumprice" query="qryPrices" selected="#YourSavedValue#"
             display="PriceTextColumn"
             display="PriceValueColumn" />
</cfform>
0
 

Author Closing Comment

by:Bang-O-Matic
ID: 33445778
Thanks for the help... worked great.
0
 

Author Comment

by:Bang-O-Matic
ID: 33448765
Agx one question, I do have a list being populated from a query, and it's all working great except, now on my form how can I get a blank " " option selected at the top of my list if no savedvalue is selected? Like I have a list of cities populated from a query in my dropdown list and I want my first selected option to be "Any City" if there was no savedvalue for this. example:

          <cfselect name = "city" query = "qryCity" value = "city" selected = "#prefillcity#">        
             <option value=" "></option>
         </cfselect>
0
 
LVL 52

Expert Comment

by:_agx_
ID: 33453312
What you have should work. You'd probably want to add the queryPosition="below" attribute too, so the blank options shows up first

<cfselect queryPosition="below" query="qryCity"  ....etc... >       
             <option value=" "></option>
</cfselect>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

856 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