User login

Theming the search bar the Agaric way

Hardcoding the Drupal search box form into the theme can result in this:

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

So customize your bar the Drupal way:

From (and we do mean stolen directly from the Drupal handbook) http://drupal.org/node/45295

Add to template.php (create if necessary)

<?php
function phptemplate_search_theme_form($form) {
  /**
   * This snippet catches the default searchbox and looks for
   * search-theme-form.tpl.php file in the same folder
   * which has the new layout.
   */
  return _phptemplate_callback('search-theme-form', array('form' =&gt; $form));
}
?>

Put your version of the below in a search-theme-form.tpl.php file. The most important part is the form key function, drupal_get_token:

<input type="text" maxlength="128" name="search_theme_form_keys" id="edit-search_theme_form_keys" size="25" value="" title="Enter the terms for which you wish to search." class="form-text" />
<input type="image" src="<?php echo base_path() . path_to_theme() . "/images/search.png"; ?>" name="op" id="edit-submitpic" value="Search" />
<input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form" />
<input type="hidden" name="form_token" id="a-unique-id" value="<?php print drupal_get_token('search_theme_form'); ?>" />

The above will be placed where <?php print $search_box; ?> is put in your page.tpl.php.

Adding the call to _phptemplate_callback or whatever to template.php and putting the above code in a separate file can be skipped in favor of hardcoding into the theme's page.tpl.php, the key is the get form token function (but this way keeps the whole thing in a file we can drop into every theme we do... well with the addition of an image file...)

Note that $directory should also have the path to theme...

More

For adding elements to the default search form (in this case separate from the search box, but should work for both) see:
http://daryl.learnhouston.com/2007/05/09/styling-drupal-5x-search-forms/

A little JavaScript of interest, try pulling the JavaScript elements from this and putting them in your search-theme-form.tpl.php. The onfocus should have an if statement or some way of only replacing the text if it's the factory-installed default, not what the user just entered:

<form action="search" method="post">
<div id="search">
<input onfocus="this.value=''" class="form-text" type="text" size="15" value=" Search" name="edit[keys]" alt="Enter the terms you wish to search for." />
</div>

</form>

from UnionWebServices' http://www.americasolidarity.org/

Hardcoding the Drupal search box form into the theme can result in this:

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

So customize your bar the Drupal way:

From (and we do mean stolen directly from the Drupal handbook) http://drupal.org/node/45295

Add to template.php (create if necessary)

<?php
function phptemplate_search_theme_form($form) {
  /**
   * This snippet catches the default searchbox and looks for
   * search-theme-form.tpl.php file in the same folder
   * which has the new layout.
   */
  return _phptemplate_callback('search-theme-form', array('form' =&gt; $form));
}
?>

Put your version of the below in a search-theme-form.tpl.php file. The most important part is the form key function, drupal_get_token:

<input type="text" maxlength="128" name="search_theme_form_keys" id="edit-search_theme_form_keys" size="25" value="" title="Enter the terms for which you wish to search." class="form-text" />
<input type="image" src="<?php echo base_path() . path_to_theme() . "/images/search.png"; ?>" name="op" id="edit-submitpic" value="Search" />
<input type="hidden" name="form_id" id="edit-search-theme-form" value="search_theme_form" />
<input type="hidden" name="form_token" id="a-unique-id" value="<?php print drupal_get_token('search_theme_form'); ?>" />

The above will be placed where <?php print $search_box; ?> is put in your page.tpl.php.

Adding the call to _phptemplate_callback or whatever to template.php and putting the above code in a separate file can be skipped in favor of hardcoding into the theme's page.tpl.php, the key is the get form token function (but this way keeps the whole thing in a file we can drop into every theme we do... well with the addition of an image file...)

Note that $directory should also have the path to theme...

More

For adding elements to the default search form (in this case separate from the search box, but should work for both) see:
http://daryl.learnhouston.com/2007/05/09/styling-drupal-5x-search-forms/

A little JavaScript of interest, try pulling the JavaScript elements from this and putting them in your search-theme-form.tpl.php. The onfocus should have an if statement or some way of only replacing the text if it's the factory-installed default, not what the user just entered:

<form action="search" method="post">
<div id="search">
<input onfocus="this.value=''" class="form-text" type="text" size="15" value=" Search" name="edit[keys]" alt="Enter the terms you wish to search for." />
</div>

</form>

from UnionWebServices' http://www.americasolidarity.org/

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.