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' => $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' => $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