Solved

Coldfusion - search form pre-fill

Posted on 2010-08-12
5
463 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
IIS 8.5 2 44
LAMP problem identifier tool ? 9 101
spamming  on Hosted svrs? 6 47
Coldfusion RegEx 8 47
The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

20 Experts available now in Live!

Get 1:1 Help Now