By ultimike on
Hello,
I recently upgraded to Drupal 4.7.4 and I'm having a problem with the search box on my site. I've narrowed it to a missing "form_token" form field but I'm unsure how to add it to the search-box.tpl.php in order to get it to show up.
I'm aware that the form_token is new to 4.7.4 to prevent cross-site scripting issues - is anyone else having this issue with custom themes and the search box?
Thanks,
-mike
Comments
There is a small article (it
There is a small article (it is pretty detailed as instructions but there are a couple of unanswered questions) regarding the custom search box:
http://drupal.org/node/45295
I ran into the same issue as you did, pasting the provided search box template:
doesn't do the job. True, you get a sort of search form that you can customize, but it is not usable. If you try searching using this custom form, you get 'no results'. Of course, it is not an indexing issue - cron has been run and search other wise works when searching using the normal template.
The normal Drupal search form and the custom one above (as provided at http://drupal.org/node/45295) are pretty much the same, but they miss the form_token form hidden field.
http://drupal.org/node/88828 provides the function form_token() to generate this field, but this function doesn't actualy exist?
A simple way to get a default token is answered by dumping the $form variable
The default token value can be found through:
PS: First post. Holla at everyone and sorry for any typos if any.
form_render
form_token exists only for Drupal 4.6.10.
Better not hardcode your form elements; take a look at form_render.
What's special about form_render, is that it marks the elements it already rendered before, so each item will be rendered only once.
Caveat: form_render marks the form array so you have to operate on the array itself.
Eg:
will look horrible because it renders the form twice. Use
You can always make small modifications to the forms array; to set for example a different description / title, whatever.
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.
Having the same problem...
Hi guys, I wonder if anyone could break this down to slightly more caveman terms... I am attempting to follow this thread and have my text editor at attention ready to hack by search-box.tpl.php ... but I am still stuck in no-search-results land at the moment.
Anyone willing to spell out a step-by-step on this one? Here's my existing broken code, as it stands:
Any help would be much appreciated.
Regards,
~J.R.
P.S. Forgot to mention, just started getting validation errors and no-results after upgrading from 4.7.2. to 4.7.4.
*Edit #2*
Ok, I noticed that advanced search was still working so by comparing the two files I was able to grab my hardcoded token value and modify the search-box.tpl.php to insert that value. Here is my updated code:
Now it passes along my token and the search works, but that is obviously quite a dumb way to do it and I am likely circumventing the new security features (a guess...I'm just a GUI designer/graphics guy fudging his way through this stuff). So I still need a tutorial on doing this properly if anyone can help. Many thanks in advance...
Won't work
While this works for you, it will fail for other users.
Use
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.
Perfect!
That was precisely the answer I was looking for. Seems to work like a charm. Thanks for the fast reply too. :)
Won't always work either
I couldn't understand why the above would not work, until I had a look at "search.module".
If the search form is a box-form you need to use "drupal_get_token('search_theme_form')".
Depends on the form_id
It indeed depends on the form_id.
It is actually best to use $search_box and style the form with a theme override (phptemplate_form_id).
--
The Manual | Troubleshooting FAQ | Tips for posting | How to report a security issue.