Solved

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

Posted on 2014-03-09
6
321 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_
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:DJPr0
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks _agx_!!
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

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 …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

762 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

6 Experts available now in Live!

Get 1:1 Help Now