Everytime i submit a search through my themes search forms i get

Validation error, please try again. If this error persists, please contact the site administrator.

I had previously hard coded this search field and obviously something changed in the search that effects my custom search form.

Heres what i had as my search form in the page.tpl.php template

<div class="search_field">								
<form action="?q=search/node/"  method="post">
<p><span class="grey">Search Example:</span> <span class="search">Port Talbot Chat </span>&nbsp;&nbsp; 
 <input type="text" maxlength="128" name="edit[search_theme_form_keys]" id="edit-search_theme_form_keys"  size="15" value="" title="Enter the terms you wish to search for." class="search" />
<input type="submit" name="op" value="Search"  class="button" />
<input type="hidden" name="edit[form_id]" id="edit-search-theme-form" value="search_theme_form"  />
</p></form></div>

Checking i see some of the ID's have changed so i altered them to look like this -

<div class="search_field">								
<form action="/search/node"  method="post" id="search_form" class="search-form">
<p><span class="grey">Search Example:</span> <span class="search">Port Talbot Chat </span>&nbsp;&nbsp; 
 <input type="text" maxlength="128" name="edit[keys]" id="edit-keys" size="15" value="" title="Enter the terms you wish to search for." class="search" />
<input type="submit" name="op" value="Search"  class="button" />
<input type="hidden" name="edit[form_token]" id="edit-form_token" value="2220bb15109dedb92c709e240dccdaf1"  />
<input type="hidden" name="edit[form_id]" id="edit-search-form" value="search_form"  />
</p></form></div>

This now works in firefox but not in Internet Explorer. Anyone tell me where i'm going wrong ?

4.7.4 is turning out to be a real headache ...

Comments

heine’s picture

Add the following code before the closing form tag.

<input type="hidden" name="edit[form_token]" id="a-unique-id" value="<?php print drupal_get_token('search_theme_form'); ?>" />

--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

desm0n’s picture

Hi Heine and thanks for getting back to me. I assumed it was to do with the token but i can't seem to get it quite right here.

I now have it outputting a unique token but its still not working using the snippet you provided.

I added your snippet in place of the <input type="hidden" name="edit[form_token]" id="edit-form_token" value="2220bb15109dedb92c709e240dccdaf1"

and tried both with the id="edit-form_token" and id="a-unique-id" but still get the same. Heres my current code -

<form action="/search/node"  method="post" id="search_form" class="search-form">
<p><span class="grey">Search Example:</span> <span class="search">Port Talbot Chat </span>&nbsp;&nbsp; 
 <input type="text" maxlength="128" name="edit[keys]" id="edit-keys" size="15" value="" title="Enter the terms you wish to search for." class="search" />
<input type="submit" name="op" value="Search"  class="button" />
<input type="hidden" name="edit[form_id]" id="edit-search-form" value="search_form"  />
<input type="hidden" name="edit[form_token]" id="edit-form_token" value="<?php print drupal_get_token('search_theme_form'); ?>" />
</p></form></div>

and my output is

<div class="search_field">								
<form action="/search/node"  method="post" id="search_form" class="search-form">
<p><span class="grey">Search Example:</span> <span class="search">Port Talbot Chat </span>&nbsp;&nbsp; 
 <input type="text" maxlength="128" name="edit[keys]" id="edit-keys" size="15" value="" title="Enter the terms you wish to search for." class="search" />
<input type="submit" name="op" value="Search"  class="button" />
<input type="hidden" name="edit[form_id]" id="edit-search-form" value="search_form"  />
<input type="hidden" name="edit[form_token]" id="edit-form_token" value="a9f44d451869610e68f64fe1f860e8e0" />
</p></form></div>

What am i missing ?
--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.

desm0n’s picture

Just to add this is hard coded into page.tpl.php, could this be the issue ? its been there for many months and never had an issue.

The token seems to be generating but the site is not validating it.
--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.

heine’s picture

My modification started from the first code block you posted, not the second. Apologies if that caused confusion.

<div class="search_field"> 
<form action="?q=search/node/" method="post">
<p><span class="grey">Search Example:</span> <span class="search">Port Talbot Chat </span>&nbsp;&nbsp; 
<input type="text" maxlength="128" name="edit[search_theme_form_keys]" id="edit-search_theme_form_keys" size="15" value="" title="Enter the terms you wish to search for." class="search" />
<input type="submit" name="op" value="Search" class="button" />
<input type="hidden" name="edit[form_id]" id="edit-search-theme-form" value="search_theme_form" />
<input type="hidden" name="edit[form_token]" id="a-unique-id" value="<?php print drupal_get_token('search_theme_form'); ?>" />
</p>
</form></div>

--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

desm0n’s picture

aha, that did the trick, many thanks for that.

However if you could, if you have the time that is, i'm curious the difference between the two bits of code. Why didn't the token work for the second bit of code and yet does for the first ?

UPDATE: ah would the second one have been

<input type="hidden" name="edit[form_token]" id="a-unique-id" value="<?php print drupal_get_token('search_form'); ?>" />

--
http://www.porttalbotchat.co.uk
-------------------------------------------------
Our mission is to discuss issues and topics of residents of Port Talbot. We provide info on events, issues, concerns and discussions of our local area.

wOOge’s picture

For trip_search (SQL Search) add this to your form instead:

<input type="hidden" name="edit[form_token]" id="edit-trip-search-form-form-token" value="<?php print drupal_get_token('trip_search_form'); ?>" />

--
wOOge | axondesignstudio.com

--
wOOge | adrianjean.ca

jenlampton’s picture

Heine, (If you're still out there) I'm having the same problem on a fresh upgrade to 5.2. My themed search form works on my dev site without any kind of edit[form_token] hidden field. But when I move my search-form.tpl.php file to the live server, I get the validation error.

When I add:

<input type="hidden" name="edit[form_token]" id="a-unique-id" value="<?php print drupal_get_token('search_theme_form'); ?>" />

to my custom template, it still works on my dev site, but when moved to the live server it still fails.

Any hints for me?
Thanks in advance,
Jen

heine’s picture

The output of FAPI changed a little in Drupal 5:

<input type="hidden" name="form_token" id="edit-search-theme-form-form-token" value="<?php print drupal_get_token('search_theme_form') ?>"  />

It's very odd that it fails on the live site and not on the dev site. Perhaps running a diff (diff -uprN folder_live folder_dev) can shed some light on this.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

jenlampton’s picture

Heine,

I think that code you supplied was for the search-box. I'm trying to theme the advanced search page. so I'd guess it needs to be more like this:

<input type="hidden" name="form_token" id="edit-search-form-form-token" value="<?php print drupal_get_token('search_form') ?>"  />

...and magically, it works now!

Jen

joeking1’s picture

hi, i might be silly, i am still a newby
i am facing the same problem, can you please explain to me how can i add print drupal_get_token('search_theme_form') to the code drupal is generating in the search form. thanks

heine’s picture

If you let drupal generate the form, there's nothing you need to do. If not, best post the code.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.

Jacob’s picture

Had the same problem on Drupal 5.5 - had 3 tabs open with the same site, got the error, Googled it and found somewhere the remedy that worked for me - just restart the browser, it seems it's something to do with cookies FAPI uses

Jacob.

TurtleX’s picture

Thank-you very much!!! This has been driving me mad and now search works perfectly.

resting’s picture

This worked for me too. Insert after the submit button.
Still won't work.

Restart browser.

Works now =D
(Drupal 5)

mikepetersonwi’s picture

I've spent hours trying to get this to work with no luck at all. I'm trying to create a custom search block that searches by node type just as if someone was using the Advanced Search (as described at code http://drupal.org/node/141788). When first running the code I received the Validation error as described in http://drupal.org/node/90808. To remedy I added <input type="hidden" name="edit[form_token]" id="a-unique-id" value="<?php print drupal_get_token('search_theme_form'); ?>" />

This resulted in this as my code:

<form action="/search/node" method="post" id="search-form" class="search-form">
<div class="form-item">
<input type="text" class="input-text" value="" size="25" name="keys" />
<input type="submit" value="Search" name="op" title="Search" alt="Search" />
<input type="hidden" name="edit[form_id]" id="edit-search-theme-form" value="search_theme_form" />
<input type="hidden" name="edit[form_token]" id="a-unique-id" value="<?php print drupal_get_token('search_theme_form'); ?>" />
<input type="hidden" name="type[knowledgebase]" id="edit-type-knowledgebase" value="knowledgebase" />
</div>
</form>

The Search form works but doesn't filter by content type (content type: knowledgebase) as I'd like it to.

I'm running Drupal 5.3, any suggestions?

Much appreciated

k.a.b.’s picture

So I have been having some troubles with this validation error and have searched like crazy for a solution to my problem. This post seems most similar and closest to a solution to my problem, but I have not been able to get it to work. I am attempting to create a custom node submission page via html and have been receiving the "Validation error, please try again" message. Within the
in my html i have placed:

<input type="hidden" name="form_token"  id="edit-page-node-form-form-token"  value="<?php print drupal_get_token('page_node_form'); ?>" />
<input type="hidden" name="form_id" id="edit-page-node-form" value="page_node_form" />

with no success. I am at a loss for answers and would really appreciate the advice! Is there a way to disable tokens for a node submission? I am using drupal 5...Thanks in advance!