Solved

ColdFusion How can I make my search page input criteria sticky?

Posted on 2014-03-09
6
328 Views
Last Modified: 2014-03-13
I have a search page with dynamic drop downs and input boxes which populates on the same page as the results.

Problem: When the results are displayed the search box is automatically reset. How can I save the last input criteria to display in the search box with the results?

Users would click on a "Clear" button to clear all the input fields.
0
Comment
Question by:DJPr0
  • 3
  • 3
6 Comments
 
LVL 52

Expert Comment

by:_agx_
ID: 39916314
Depends on how you're submitting the form: ajax or regular page submit. If it's a regular form submit just use the URL/FORM fields to populate to input field "value".

Note: If you're using method=post, change the scope from URL to FORM

           <!--- set defaults so the fields always exist --->
           <cfparam name="URL.input1" default="">
           <cfparam name="URL.input2" default="">
           ....
           <!--- use values to populate fields --->
           <form method="get" ...>
             <cfoutput>
              <input type="text" name="input1" value="#URL.input1#">
              <input type="text" name="input2" value="#URL.input2#">
             </cfoutput>
           </form>
0
 

Author Comment

by:DJPr0
ID: 39916406
Thanks for your reply _agx_

I'm using method=post

Also my "Clear" button stopped working to refresh the fields.

How can I apply to binded and query dropdowns:

<select name="discipline3" style=width:172px;>
        <option value="ALL">ALL</option>
         <cfoutput query="DropDown2">
           <option value="#DropDown2.vendor#">#DropDown2.vendor#</option>
         </cfoutput>
     </select></td>
      <td>Project</td>

<td><cfselect name="discipline4" style=width:154px; title="Press and hold Ctrl key to select multiple projects" multiple>
      <option value="ALL">ALL</option>
      <cfoutput query="DropDown4">
          <option value="#DropDown4.ProjNum#">#DropDown4.ProjNum#</option>
        </cfoutput>
        <cfselect name="discipline4"
                bind="cfc:MyComponent3.getProjects( {discipline1} )"
                value="ProjNum"
                display="ProjNum"
                multiple="Yes"/>
                  </cfselect></td>
0
 
LVL 52

Assisted Solution

by:_agx_
_agx_ earned 500 total points
ID: 39916533
> How can I apply to binded and query dropdowns:

With non-bind selects, just compare the values within the query loop:

        <cfoutput query="DropDown2">
              <option value="#DropDown2.vendor#"
                      <cfif DropDown2.vendor eq FORM.discipline3>selected</cfif>
                > #DropDown2.vendor#</option>
         </cfoutput>        

For bound selects in CF9+ use the "selected" attribute .

       <cfselect name="discipline4"  selected="#FORM.discipline4#" .... >

 (Edit) If you're using an earlier version than CF9, you'll have to do the bind part manually. Just do a search on "cfselect bind selected" and you'll find a bunch of examples.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:DJPr0
ID: 39925176
Works good _agx_, except for the multiple selection - if one is selected it works fine.
If two selections are made, it defaults to "ALL".

Multiselect code:

<cfselect name="discipline4" style=width:154px; title="Press and hold Ctrl key to select multiple projects" multiple>
      <option value="ALL">ALL</option>
      <cfoutput query="DropDown4">  
          <option value="#DropDown4.ProjNum#"          
           <cfif DropDown4.ProjNum eq FORM.discipline4>selected</cfif>
           >  #DropDown4.ProjNum#</option>          
        </cfoutput>
        <cfselect name="discipline4" selected="#FORM.discipline4#"
                bind="cfc:MyComponent3.getProjects( {discipline1} )"
                value="ProjNum"
                display="ProjNum"
                multiple="Yes"/>
                  </cfselect></td>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39925188
Oh, if the list supports multiple you'll need to use list functions instead of EQ:

<cfif listFindNoCase(FORM.discipline4, DropDown4.ProjNum)>selected</cfif>

Not sure about binds.. it *should* automatically work if you use the "selected" attribute in CF9+. That is assuming Adobe programmed it correctly ...
0
 

Author Closing Comment

by:DJPr0
ID: 39926715
Thanks _agx_!!
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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

914 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

18 Experts available now in Live!

Get 1:1 Help Now