x
 
Create New Page
 View Previous Changes    ( Last updated by stinhambo )

Putting exp:search:keywords in a hidden field

Problem

If you want to use the current search keyword in another form then you might think that this line would cut it -

{exp:search:simple_form}
    
<input type="hidden" name="keywords" value="{exp:search:keywords}" />
{/exp:search:simple_form}

But ExpressionEngine being a secure system creates a hash code instead so your HTML looks like this -

<input type="hidden" name="keywords" value="M10o93H7pQ09L8X1t49cHY01Z5j4TT91fGfr" />

Solution

There is a plugin called Reeposition which allows you to grab the contents of a tag such as {exp:search:keywords} and reuse it anywhere on the template without having to envoke the tag over and over. Especially useful for looping tags but that’s another story.

So assuming you have downloaded and added the plugin to your system directory (assuming it is still called the system), just envoke Reeposition in the template by wrapping it in this code -

{exp:reeposition}
code
{
/exp:reeposition}

The form code

Armed with this information I guess you want to see how it’s done!

Well here is the template that delivers results -

{exp:reeposition}
{reeposition
:item}{exp:search:keywords}{/reeposition:item}
    
<h2>Search Results for {reeposition:put_item}</h2>
    
{exp:search:simple_form}
        
<input type="hidden" name="keywords" value="{reeposition:put_item}" />
    
{/exp:search:simple_form}

code
...

{/exp:reeposition}

What happened here?

1. The Reeposition plugin was envoked with {exp:reeposition}{/exp:reeposition}
2. The tag I wanted to extract the value from is wrapped with

{reeposition:item}{/reeposition:item}

This places the value into…
3. {reeposition:put_item}. You can reuse this as many times in the template as you want by obviosly between the tag pair in step one.
4. I put {reeposition:put_item} as the value in a hidden field.

Category:Search
Category:Plugins
Category:Security

Categories: