JHollanti
JHollanti

Reputation: 2413

Drupal 7 search parameters

I want to create a custom search box and use that to interact with Drupal's search module. Currently everything works pretty well. However, i would also need to use a proper token with the search. I have no idea what key Drupal uses to form this token.

Currently i have:

 <form class="search-form" action="/search/node" method="post" id="search-form" accept-charset="UTF-8">
   <input type="text" name="keys" class="search_box" value="Search ..." />
   <input type="hidden" name="form_id" id="search-form" value="search_theme_form" />
   <input type="hidden" name="form_token" value="<?php print drupal_get_token('search_theme_form'); ?>" />
 </form>

This works well enough to display the results of one page. If i try to navigate to the second results page, all the results are thrown away.

Upvotes: 2

Views: 4398

Answers (3)

Behzad-Ravanbakhsh
Behzad-Ravanbakhsh

Reputation: 972

And in theme use:

<?php
 $form = drupal_get_form('search_block_form');
 echo  render($form);
 ?>

Upvotes: 0

JHollanti
JHollanti

Reputation: 2413

It turned out to be as simple as changing the form from post to get. Here's the html for a working solution.

<form class="search-form" action="/search/node" method="post" id="search-form" accept-charset="UTF-8">
  <input type="text" name="keys" class="search_box" value="Search ..." />
</form>

You don't need to define tokens or anything of the sort.

Upvotes: 1

Dave Reid
Dave Reid

Reputation: 1270

You should probably use the more proper

 $form = drupal_get_form('search_block_form');
 return drupal_render($form);

http://api.drupal.org/api/drupal/modules--search--search.module/function/search_form/7

Upvotes: 1

Related Questions