Theme Drupal 6 Search Box
Originally this topic was going to be about how I have been banging my head for hours on my desk trying to figure out how to override the Drupal 6 default search box form (search-theme-form.tpl.php), but as I started to type this up I was checking old pages for information and low and behold I found the answer. So instead I decided to write a post which contained many instances of all the keywords I used when searching for the solution to this very problem in hopes that some other people will find it beneficial.
This post applies to overriding all templates of core modules in Drupal 6.
The following links are very beneficial, and are what lead to my salvation in this endeavor.
Overriding the default search box in Drupal 6.
Core templates which can be overridden.
Preamble
In Drupal's previous life, 5.x, overriding a template required a function to notify the core that you wanted to override a template file. This was where template.php came into play. In Drupal 5.x the template.php file would notify the core via a callback function and specify that 'search-theme-form' was to be overridden locally by the theme. Then you could create a file in the theme's directory named 'search-theme-form.tpl.php' and the core would read this one in instead of the default given to it by the module. You can read more about this Drupal 5 search box override. This is no longer the case! I'm sure that the developing community had good reason for not making Drupal 6 backwards-compatible with this method, and in the long run I'm sure it probably saves some processing time as well.
Basic Steps
- Copy the original file from the module's directory into your theme directory
('modules/search/search-theme-form.tpl.php' --> 'themes/wonderbread/search-theme-form.tpl.php')
- Rename the new file in your theme directory by replacing all hyphens with underscores
('search-theme-form.tpl.php' --> 'search_theme_form.tpl.php')
- Make any changes to the theme file and save it
- Rebuild your theme registry
Clear button located at "Administer > Site configuration > Performance".
That's it! And to think I wasted so much time on this...
Note: One reason I had to do this was because I needed to get rid of those starting words before the search box. A simple PHP function you can use in you newly modified search_theme_form.tpl.php file is below.
<div id="search" class="container-inline">
<?php print str_replace('Search this site:','',$search_form);?>
</div>
very nice
It help me a lot, thanks!!
Yeah..its a shame i can not
Yeah..its a shame i can not modify the form-array before processing, as i can do with the user_login_box....
i agree, Here is the Best solution for it
i agree to waldmaeister.
you may find more reliable and best way on: http://ahsangill.wordpress.com/2009/04/29/drupal-6-custom-search-box/
Does the above create a "?" character for anybody else?
I get a "?" character next to the search box when using the str_replace string used above. I tried using an like below but still get a question mark.
str_replace('Search this site:',' ',$search_form);instead of
str_replace('Search this site:','',$search_form);Better solution
Here's a better way to remove the text "search this site:"
In template.php, add this code
<?php
// REMOVE "SEARCH THIS SITE" TEXT FROM KEYWORD SEARCH
function phptemplate_form_element($element, $value) {
if ($element['#title'] == t('Search this site')) {
unset($element['#title']);
}
}
?>
I'm curious about
I'm curious about something-- is it really 'better' to evaluate every single form element on every single page to see if the title is "search this site"? I would think on a large form with lots of elements being filled out by lots of people that could have some performance implications.
===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz
Good question
Well, firstly, that first method didn't work without leaving a "?" to the left of the input field.
But your question about the implications on performance is interesting. There's some controversy about the performance toll the drupal hook system takes on a site (see http://20bits.com/articles/4-problems-with-drupal). I'm not sure what would be considered the "cleaner" way of removing that text. Maybe I am on the wrong path as well. Anybody else weigh in on this?
I think this is a bad way to
I think this is a bad way to modify a single form element like this, iterating over all elements on your site, but I think its a brilliant idea nonetheless, because you could use this if you must use image-type submit buttons. You could use this function to look for all submit buttons that have value="submit" and change them to image type, and load submit.gif.
-------------------------------
peach from All Drupal Themes
This does not work.
Strangely enough, this code in template.php just removes all form elements in my complete website (checkboxes, textareas, radio buttons,... they are all gone). It is a D6 website, multilingual. I do not see why.
better way
A better way would be to use the preprocess functions, as explained in this codegobbler post. Something along the lines of the following should work:
/**
* Override or insert PHPTemplate variables into the search_theme_form template.
*
* @param $vars
* A sequential array of variables to pass to the theme template.
* @param $hook
* The name of the theme function being called (not used in this case.)
*/
function phptemplate_preprocess_search_theme_form(&$vars, $hook) {
// Modify elements of the search form
unset($vars['form']['search_theme_form']['#title']);
}
--
Drupal Theme Developer’s Cheat Sheet | 45 Screencasts to Get You Kicking Ass with Drupal
which is the solution for this problem myDRU??
I do not see why, this code in my template remove all form elements and after this when i delete the code from my template I get an error that refers to this function:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'phptemplate_form_element' was given in C:\xampp\htdocs\drupal\includes\theme.inc on line 617.
Do you have the solution?
Thanks.
why don't you use
why don't you use http://drupal.org/project/custom_search_box
Luis
Yes but....
Yes I use Custom_search and it is the better solution but i wanted to solve the problem that I had come to put this function and in the end I had to reinstall drupal with their modules, etc ...
Thanks.
This is not a BETTER but a BITTER Solution!
sorry, but it appears me so.
I keep getting a Fatal
I keep getting a Fatal error: Call to undefined function _phptemplate_callback() in template.php after following the above directions.
I didn't have to rename my
I didn't have to rename my file.
My search-theme-form.tpl.php is still the same name.
How does one go about getting rid of the submit button in favor of placing an image or javascript link?
--
Michael Bishop
replacing the button with an image
This can be done with css. Something like:
.form-submit {background: url(images/button_go.png) no-repeat 0 0;
border: none;
}
will work (although you'll probably want to add width/height/padding/etc). Then something like:
.form-submit:hover {border: 1px solid gray;
}
to change the hover state. This will change ALL of your submit buttons, so if you don't want that, be sure to specify which one you do want (ie. #header .form-submit to get it to only apply to buttons in the header)
btw, I didn't have to change the hyphens to underscores either.
I want to get rid of the
I want to get rid of the submit button all together.
CSS override isn't ideal.
I'd like to be able to put my own markup there. An image background would work if I didn't have to use a custom type face on the button itself.
I tried looking for "unset submit button" to no avail.
Thanks for the reply!
--
Michael Bishop
perhaps this might be
perhaps this might be useful: Theming The Search Submit Button
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Thanks Word, that link is
Thanks Word, that link is killer!
I think that is what I will do.
Still looking for a way to effect the markup of the form though.
--
Michael Bishop
i just realized you're on
i just realized you're on d6-- if you go to the modules/search directory, there should be a bunch of tpl files there. Find the one that has the code you want to change, copy it to your theme's directory, and edit away. see http://drupal.org/node/190815 for more info.
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Yup. Tried that. The tpl
Yup. Tried that.
The tpl has:
<div class="container-inline"><?php print $search_form; ?>
</div>
In the comments it says in the comments
* - $search['search_block_form']: Text input area wrapped in a div.* - $search['submit']: Form submit button.
* - $search['hidden']: Hidden form elements. Used to validate forms when submitted.
The label is part of the entire ['search_block_form'].
I'd like to remove that (Doing so with the str_replace like above)
I've hard coded:
<input src="myimage.png" ..[form controls].. >and plugged in the id of the form statically but it just feels hacky.
Also, the tpl is search-theme-form.tpl.php and not search-block-form.tpl.php.
My page.tpl.php is using:
<?php if ($search_box): ?><div id="search-box">
<?php print $search_box; ?>
</div> <!-- /#search-box -->
<?php endif; ?>
My assumption was that it would use search-block-form.tpl.php but alas it does not.
--
Michael Bishop
You can just manually code
You can just manually code the entire form yourself-- then you can alter the markup anyway you want. These are the elements required for the form itself:
<?php<label for="search_theme_form">Custom Search</label>
<input type="text" name="search_theme_form" id="edit-search-theme-form-l" size="25" value="" title="Enter the terms you wish to search for." class="form-text" />
<input type="submit" name="op" value="GO!" />
<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'); ?>" />
?>
Then just add whatever other divs/spans/classes/ids you want. This should work in either search-block or search-theme (you just need to change the classes/ids appropriately).
===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime." -- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz
Great simple code... I am
Great simple code... I am also trying to hard code a php search box in the header of a user list view. However, I cannot get it to work properly.
Is it possible with the code to create a combine two-in-one user search looking in both user data and user profile?
Any suggestions?
This definitely the easiest way to do this - thanks
Spent half the day yesterday and all of this morning figuring out how to get rid of the "Search this site:" text and use an image for the search button. The str_replace() methods listed in some posts worked but those are bad hacks prone to failure any time Drupal is updated.
Your code made it super easy to get rid of the text and change the submit button to an image, thanks!
search-theme-form.tpl.php
<div id="search" class="container-inline"><input type="text" name="search_theme_form" id="edit-search-theme-form-l" size="25" value="" title="Enter the terms you wish to search for." class="form-text" />
<input type="image" class="form-submit" value="" id="edit-submit" name="op" src="/images/search-fp.gif"/>
<?php
print $search["hidden"];
?>
</div>
I kept the default $search["hidden"] just because...
Easy way to do this is css
Easy way to do this is css is simpy to use #search label {display: none;} very easy and no fiddling around with theme functions etc.
Do you have to assign the
Do you have to assign the form an action when you implement it in this way?
If you have your page.tpl for example with just $print search_box; somewhere then you lose the ability to define the search options right? So do you have to then add a form action of say /node/search ?
Web Developer
Music Photographer
Can't get the search term to pass to the actual search function
I've followed these directions and read many, many posts on this topic and still cannot get my template search to work.
When I remove search-theme-form.tpl.php, the search works correctly but doesn't line up on my page correctly.
When I add it back in, the search term does not get passed to the search form and instead loads a blank search page.
<div id="edit-search-theme-form-1-wrapper" class="form-item">
<label for="search_theme_form_keys" class="search-labe">Search</label>
<input type="text" maxlength="128" name="search_theme_form_keys" id="edit-search-theme-form-1" size="25" value="" title="Enter the terms you wish to search for." class="form-text" />
<input type="submit" name="op" class="form-submit" value="Go" />
<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'); ?>" />
</div>
Any suggestions?
Does anyone know how to
Does anyone know how to filter content type or category in the search_theme_box in Drupal 6?
search-block-form.tpl.php only works
Hi, for me only copying and editing search-block-form.tpl.php worked. Also I didn't change the - to _. I'm quite new to Drupal though, should I? The developer module also gives as module suggestion 'search-block-form.tpl.php' and nothing with underscores.
Thanks
I spent some time searching for this too, and wouldn't have thought of the str_replace trick right away (was trying to find a way to modify the raw search form array).
For anyone who is looking for a simple way to resize the search box in drupal 6 - follow the above instructions and use this code or similar:
<div class="container-inline"><?php print str_replace('size="15"', 'size="25"', $search_form); ?>
</div>
IMO this approach is better than hard coding the whole search form, even if you have a few attributes you wish to change. (View source of rendered search form, find the text you wish to change, and call str_replace as needed to produce the desired output.)
An even better method for drupal 6
The best way to override a form in the theme layer is imho the method suggested by lullabot.
So to get rid of the title of the search form by just using your template.php, you have first identify the form you want to overide, and then, overide it. Here is the code to drop in your template.php (without the php opening and closing tags, and remember to replace 'mytheme' by your theme name):
<?php/**
* Override of the Search Box for d6
* first, select the form ID
*/
function mytheme_theme() {
return array(
// The form ID.
'search_theme_form' => array(
// Forms always take the form argument.
'arguments' => array('form' => NULL),
),
);
}
/**
* Theme override for search form.
* The function is named themename_formid.
* more infos : <a href="http://www.lullabot.com/articles/modifying-forms-5-and-6
" title="http://www.lullabot.com/articles/modifying-forms-5-and-6
" rel="nofollow">http://www.lullabot.com/articles/modifying-forms-5-and-6
</a> * Here is where you can modify the selected form
*/
function mytheme_search_theme_form($form) {
// deactivate the title of the form
unset($form['search_theme_form']['#title']);
$output .= drupal_render($form);
return $output;
}
?>
You could also remove the submit button by adding
unset($form['submit']);to the sencond function (after the first unset).You can change the size of the input with this :
$form['search_theme_form']['#size'] = 25;or even set a default value like this :
$form['search_theme_form']['#value'] = 'search';.And the best part, if you want a default value, and that default value disapear when typing :
$form['search_theme_form']['#value'] = 'search';$form['search_theme_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = 'search';}", 'onfocus' => "if (this.value == 'search') {this.value = '';}" );
Ok, this is awesome, but to make it perfect, a little bit of css magic to adapt the colors :
#edit-search-theme-form-1{color:#ccc;
}
#edit-search-theme-form-1:focus{
color:#000;
}
There you go!
sources:
http://www.lullabot.com/articles/modifying-forms-5-and-6
http://www.brightcherry.co.uk/scribbles/2008/12/04/html-form-effect-remo...
____________________________________________________________
en: www.couzinhub.com
fr: www.couzinhub.com
Now if you could repeat that
Now if you could repeat that in simple "don't have a clue" english, it would save me from beating my head against the wall lol.
Do we have to edit the code or just copy/past to template file. Those extras you gave where in the code are we suppose to list it.
>>>>>>>>>>>>>>>>>>>>>>>
contemplating the meaning of existence, what else would I be doing
Aaahh don't bang you're head
So in "don't have a clue" version:
This snippets should be copy and pasted in the template.php file of your theme, and DON'T copy the php opening and closing tags. In order to make it work, you have to replace every instance of 'mytheme' by the name of your theme. For example, if your theme is called 'basic' :) you have to rename the two functions like this :
function basic_theme()... andfunction basic_search_theme_form($form)...This snippet works in two steps, the first one is :
<?php
/**
* Override of the Search Box for d6
* first, select the form ID
*/
function mytheme_theme() {
return array(
// The form ID.
'search_theme_form' => array(
// Forms always take the form argument.
'arguments' => array('form' => NULL),
),
);
}
?>
Then, the second step is where you define the modifications to the search box. I commented each line so it makes more sense
<?php
/**
* Theme override for search form.
* Paste this in the template.php file of your theme
* more infos : lullabot.com/articles/modifying-forms-5-and-6
* Here is where you can modify the selected form
*/
function mytheme_search_theme_form($form) {
// this line deactivate the 'search this site' label - you can change/delete this
unset($form['search_theme_form']['#title']);
// remove the submit button - you can change/delete this
unset($form['submit']);
// Change the size of the search box (you can change the value '25 to whatever you want) - you can change/delete this
$form['search_theme_form']['#size'] = 25;
// Set a default value in the search box, you can change 'search' to whatever you want - you can change/delete this
$form['search_theme_form']['#value'] = 'search';
// Additionnaly, hide the text when editing - you can change/delete this
// Remember to change the value 'search' here too if you change it in the previous line
$form['search_theme_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = 'search';}", 'onfocus' => "if (this.value == 'search') {this.value = '';}" )
// Don't change this
$output .= drupal_render($form);
return $output;
}
?>
Additionally, you can use a little bit of css to make the text gray when it's not active, and black when the user is typing in the search box. Copy and paste this in the css file of your theme (usually style.css)
#edit-search-theme-form-1{color:#ccc;
}
#edit-search-theme-form-1:focus{
color:#000;
}
Hope this makes more sense :)
____________________________________________________________
en: www.couzinhub.com
fr: www.couzinhub.com
I get an error
I get an error message,
Parse error: syntax error, unexpected T_VARIABLE
>>>>>>>>>>>>>>>>>>>>>>>
contemplating the meaning of existence, what else would I be doing
Woups, my bad, forgot a
Woups, my bad, forgot a semi-colon at the end of the attributes line, here it is :
(again, replace 'mytheme' by your theme name and don't copy the php opening and closing tags)
<?php
/**
* Override of the Search Box for d6
* first, select the form ID
*/
function mytheme_theme() {
return array(
// The form ID.
'search_theme_form' => array(
// Forms always take the form argument.
'arguments' => array('form' => NULL),
),
);
}
/**
* Theme override for search form.
* Paste this in the template.php file of your theme
* more infos : lullabot.com/articles/modifying-forms-5-and-6
* Here is where you can modify the selected form
*/
function mytheme_search_theme_form($form) {
// this line deactivate the 'search this site' label - you can change/delete this
unset($form['search_theme_form']['#title']);
// remove the submit button - you can change/delete this
unset($form['submit']);
// Change the size of the search box (you can change the value '25 to whatever you want) - you can change/delete this
$form['search_theme_form']['#size'] = 25;
// Set a default value in the search box, you can change 'search' to whatever you want - you can change/delete this
$form['search_theme_form']['#value'] = 'search';
// Additionnaly, hide the text when editing - you can change/delete this
// Remember to change the value 'search' here too if you change it in the previous line
$form['search_theme_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = 'search';}", 'onfocus' => "if (this.value == 'search') {this.value = '';}" );
// Don't change this
$output .= drupal_render($form);
return $output;
}
?>
And if you're overiding the BLOCK search form and not the theme on, use this:
<?php
/**
* Override of the Search Box for d6
* first, select the form ID
*/
function mytheme_theme() {
return array(
// The form ID.
'search_block_form' => array(
// Forms always take the form argument.
'arguments' => array('form' => NULL),
),
);
}
/**
* Theme override for search form.
* Paste this in the template.php file of your theme
* more infos : lullabot.com/articles/modifying-forms-5-and-6
* Here is where you can modify the selected form
*/
function mytheme_search_block_form($form) {
// this line deactivate the 'search this site' label - you can change/delete this
unset($form['search_block_form']['#title']);
// remove the submit button - you can change/delete this
unset($form['submit']);
// Change the size of the search box (you can change the value '25 to whatever you want) - you can change/delete this
$form['search_block_form']['#size'] = 25;
// Set a default value in the search box, you can change 'search' to whatever you want - you can change/delete this
$form['search_block_form']['#value'] = 'search';
// Additionnaly, hide the text when editing - you can change/delete this
// Remember to change the value 'search' here too if you change it in the previous line
$form['search_block_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = 'search';}", 'onfocus' => "if (this.value == 'search') {this.value = '';}" );
// Don't change this
$output .= drupal_render($form);
return $output;
}
?>
note for Katbailey: I know, javascript inline isn't the best practice... sorry!
____________________________________________________________
en: www.couzinhub.com
fr: www.couzinhub.com
In a module
I want to use this feature in a module. In the following line instead of text 'Search...' I want to use a php variable. How would I go about this?
$form['search_block_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = 'search';}", 'onfocus' => "if (this.value == 'search') {this.value = '';}" );How would you implement this in search-block-form.tpl.php?
This code is great, really easy to adapt. But I'd like to add some div's in there so I can get the layout perfect. In the past I've found that easier to do by using tpl.php files than adding loads of functions in template.php... Can I alter the
<?php print $search_form; ?>in search-block-form.tpl.php to something else so that I can use BOTH this snippet AND search-block-form.tpl.php??Hi All, Here's another way
Hi All,
Here's another way of doing the same thing. It's based on overriding preproccess functions. Add this function to the template.php file of your theme. Remember to remove the
<?php...
?>
<?php
function {theme_name}_preprocess_search_theme_form(&$variables) {
$variables['form']['search_theme_form']['#title'] = '';
$variables['form']['search_theme_form']['#size'] = 25;
$variables['form']['search_theme_form']['#value'] = 'search';
$variables['form']['search_theme_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = 'search';}", 'onfocus' => "if (this.value == 'search') {this.value = '';}" );
unset($variables['form']['search_theme_form']['#printed']);
$variables['search']['search_theme_form'] = drupal_render($variables['form']['search_theme_form']);
$variables['search_form'] = implode($variables['search']);
}
?>
Nathan.
It's working perfectly!
It's working perfectly! Drupal 6.10
Modified for block
Thank you Nathan, this works best for me. I have made an update to your code snippet to work on blocks as well as adding the php variable into the javascript to eliminate the need to re-enter the same thing multiple times.
<?php
function sareen_preprocess_search_block_form(&$variables) {
$variables['form']['search_block_form']['#title'] = '';
$variables['form']['search_block_form']['#value'] = 'Search';
$variables['form']['search_block_form']['#attributes'] = array('onblur' => "if (this.value == '') {this.value = '".$variables['form']['search_block_form']['#value']."';}", 'onfocus' => "if (this.value == '".$variables['form']['search_block_form']['#value']."') {this.value = '';}" );
unset($variables['form']['search_block_form']['#printed']);
$variables['search']['search_block_form'] = drupal_render($variables['form']['search_block_form']);
$variables['search_form'] = implode($variables['search']);
}
?>
Joe
www.kobo.com.au
Awesome snippet
great snippet.
Hi guys, I cant get my theme
Hi guys,
I cant get my theme to change using any of these methods above, im using drupal 6 and the clean theme. Ive tried simple stuff like changing the div name and clearing the cache but nothing seems to be working. Anyone experienced similar?
Cheers.
Garry Bain, sdesign1
Drupal Experts
phptemplate_preprocess_search_theme_form() won't work
Just check this pdf doc:
http://drupal.org/files/theme_flow_6_1.pdf
It shows obviously that engineName_preprocess_hook() will be called after template_preprocess_hook(). That means in this case, the form has already been generated when it goes into engineName_preprocess_hook() which is defined in template.php. Because it's form, you cannot render it twice and expect second round overrides first round.
In this thread this one works for me. I think this is the best approach:
http://drupal.org/node/224183#comment-1223234
xell, It's working fine for
xell,
It's working fine for me. I'm using Drupal 6.9 if that makes any difference.
Nathan.
Search box to filter by content type
If you want to want your search box to be able to filter the search by content types, modify this code as needed in page.tpl.php or possibly in search-theme-form.tpl.php (haven't tested it here).
<form action="<?php echo $base_path; ?>search/node" method="post" id="search-theme-form"><div id="search">
<input type="text" class="form-text" id="edit-search-theme-form-1" value="search..." size="15" onclick="this.value = ''" onblur="if (!this.value) this.value = 'search...'" name="keys" />
<input type="submit" value="GO" name="op" title="Search" class="form-submit" alt="Search" />
<input type="hidden" value="<?php print drupal_get_token('search_form'); ?>" name="form_token" />
<input type="hidden" value="search_form" id="edit-search-form" name="form_id" />
<br />
<div class="checks">
<input type="checkbox" name="type[ContentType1]" id="edit-content-type-1" value="ContentType1" /> ContentType1
<input type="checkbox" name="type[ContentType2]" id="edit-content-type-2" value="ContentType2" /> ContentType2
</div>
</div>
</form>
You can add as many content types as you want of course. This example has no title, has a default value in the text input box of "search..." and uses the word "go" on the submit button, while displaying 2 checkboxes underneath to filter the search by those content types. Replace ContentType1 and 2 with whatever content type you want to filter by.
Just easier to do this if...
If you're not planning on having the search box be toggled per taxonomy or other variable, this is the easiest way to do it. You get exactly what you want without any fuss or overhead.
Thanks Markku!
thanks a lot !!! I've spend a
thanks a lot !!!
I've spend a lot of time trying to understand how overriding works, and with the different processes (according to the versions) it was very confusing. Even if not everything is perfect, it helps!
Add a taxonomy selector to the core search block
This seems like a really common feature on a lot of sites, and I thought it would just be a matter of adding the selctor in hook_form_alter and the rest would just happen. Wrong. search_block and search advanced have nothing in common.
Apparently it can also be done with views etc, but I just wanted a selector added to the normal search block. NOT EASY.
But done.
My version is at : http://cvs.drupal.org/viewvc.py/drupal/contributions/sandbox/dman/search...
It may make a project unless someone points out that it's really a lot easier than I thought....
.dan.
WOW!! You guys are awesome. I
WOW!! You guys are awesome. I have been looking all over for this, and those links are very helpful. I do have a couple of issues that are keeping me from applying this and testing this method out. I do not have a template.php file. Of coarse I had to choose the theme (dreamy) that does not have one. Grrr... Is this still going to work for me? If so, where to I place the code? I am assuming I just need to put it in my page.tpl.php file? I dunno. Also, I am not trying to completely get ride of the "search this site" text, rather I want to place it inside of the search box, and have it disappear once you click on it. If anyone has suggestions on how to make that work, or lead me in the right direction that would be great! Right now I am working with the only other information I have found that might be of help to you guys here. I am using drupal 6.10 if that makes a difference. Thanks.
_
There's a few of snippets on this page-- they go in different places. Read the individual comment and/or it's parents to see what goes where.
As for the template.php file-- if your theme is a phptemplate engine based theme (and most are these days) you can just create one if it doesn't exist yet.
_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.
Easiet way yet.
For those of you still having trouble. I have created a module to do this. It allows you to change the settings. It is still in dev but should be stable enough for production. Just awaiting some testing.
http://www.drupal.org/project/custom_search_box
subscribing
subscribing
Luis
sweet module
Nothing easier! Thanks!
Hide Search button
I'd like to hide the search button altogether. I want only the text box displayed and when you type in terms and hit enter it forwards to the search results.
I have tried #type hidden with no luck. Any help is appreciated.
Read the thread, it's already
Read the thread, it's already all in there
____________________________________________________________
en: www.couzinhub.com
fr: www.couzinhub.com
Need to remove the space between text box and search button
I need to remove the space between the text box and search button.
Basically the text box and submit button "image" should be touching each other.
Is this possible? Do I need to over ride the search box and/or button?
Can anyone here help me with the code.
I'm using D6 with theme.
Thanks for any help...
@ Gustavson: You will be
@ Gustavson: You will be wanting to do some CSS modifications/additions to your theme's style.css file to make that happen.
@ Everybody: interested in a simple module for this type of customization, there is a new module called Custom Search Box and I have found it very helpful. It's not finished yet, but it works for most people's needs in this thread. I have implemented it quite successfully and the module will only get better as it grows older. :)
EDIT: Just saw Jweberg's post on March 19, 2009
Search This Site - 2 seconds
.form-item label
display:none;
}
well...
That's a really bad way, not only you forgot to open a bracket, making your code wrong, but if you do this, you won't have any form label, not only in the search box, but in the entire site...
Be just more specific with you selector :
#search label {display:none;
}
And again, it is always better to remove the html from the output than hide it with CSS. Display :none; is not the best friend of search engines.
____________________________________________________________
en: www.couzinhub.com
fr: www.couzinhub.com
But what about the word "Search" above the label/form for search
I'm trying to figure out how to delete the word "search" that is directly about the Search This Site (default) [ box 4 search term] and submit button. Using the custom search module I can modify everything except the word Search which seems to be a title, e.g.
Search
search this site [ box 4 search term] submit button
It's that first "Search" I'm wanting to delete. Anybody done this? Know how? I read all of the search files in the module for search. My failure to understand php at the needed level left me empty-handed...couldn't find the text I want to be rid of.
Help?
( EDIT ... ADDITION: From Firebug, this is the code in template.php:
<div id="block-search-0" class="block block-search"><h2>Search</h2>
<div class="content">
<form id="search-block-form" method="post" accept-charset="UTF-8" action="/">
Do you mean like what happens
Do you mean like what happens when you enter
<none>in the search block administer screen?.dan.
OMG..how stupid
of me. I've been so focused on the modifying the search settings through the Administer/By Module/Search/Search Settings page that I completely overlooked the search-form block configuration setting. Agggh. I'm embarrassed! I typed in on the latter page and voila, I got what I wanted. Now I have to remember, though, that I change that settinig on the search-form block configuration page while I change the search box label and default text inside the search form on the Search Settings page.
Thank you so very much for this advice!!!
:-B
As usual with Drupal, it's knowing where to look...
.dan.
Well, It works when I use
Well, It works when I use simply call as a block.
But when I use module_invoke, it still appears. I mean, I am trying to use this search-block using magic tabs,
Search
appears.
Any suggestions?
This 'search' is the title of
This 'search' is the title of the block, so it simply controled by thr block template (block.tpl.php).
You can create a copy of this template, and call it 'block-search-0.tpl.php' or block-search.tpl.php and in this template, remove the title.
____________________________________________________________
en: www.couzinhub.com
fr: www.couzinhub.com
If one reason you need, like
If one reason you need, like the original poster, is to remove or customize the label "Search this site:", drupal 6 arrived with the hidden gem on your settings.php, find and activate the last section, String overrides:
$conf['locale_custom_strings_en'] = array(# 'forum' => 'Discussion board',
# '@count min' => '@count minutes',
'Search this site' => '',
);
Your label will be wiped out even from the source, or change it to something else. Or else use stringoverrides.module, especially if you are still on drupal 5.
Another good example is to simplify everything you imagine:
'Create new account' => 'Join',
'Request new password' => 'Lost?',
'Add new comment' => 'Discuss',// perhaps Review
'Comments' => 'Discussions',
'Post new comment' => 'Discuss', //perhaps What do you think?
'Submit' => 'Post',
'Enter the terms you wish to search for.' => 'Search my awesome site',
'There is currently %members and %visitors online.' => '%members & %visitors',
'There are currently %members and %visitors online.' => '%members & %visitors',
'Spaces are allowed; punctuation is not allowed except for periods, hyphens, and underscores.' => '',
'A valid e-mail address. All e-mails from the system will be sent to this address. The e-mail address is not made public and will only be used if you wish to receive a new password or wish to receive certain news or notifications by e-mail.' => '',
Another approach might be CSS as mentioned somewhere above or with jQuery, jquery.example plugin is the shortest way. The approach may vary depends on your intention and familiarity.
love, light n laughter
gausarts
Thank you Gusarats. I'm
Thank you Gusarats. I'm changing the Search This Site label easily by using the Custom Search Box module. It appends settings to the Search Settings page where you can leave a field box blank, for example, and remove the Search This Site verbiage, with just one click. It's a nice module.
CSS approach
Sorry, I didn't actually see this covered above...
To simply hide items from the Search block, just include this CSS in styles.css (or another CSS file your theme includes):
/* Don't display block title */
div.block-search h2 {
display: none;
}
/* Don't display search label */
div.block-search label {
display: none;
}
/* Don't display search button */
div.block-search .form-submit {
display: none;
}
You could also use CSS to e.g. put a picture of a magnifying glass inside the search input.
With this method, there's no need to use function overrides or custom template files. You would not be able to change any text of course, just hide or show it.
-Karlheinz
for accessibility reasons,
for accessibility reasons, I'd advise you people not to str_replace the title, and not to unset the title altogether since this will either lead to an empty label or no label
labels are important to blind people and others that use a screen reader, so please do not remove them
also using display:none; causes most screen readers to entirely drop the element, therefor I'd advise you to use position:absolute;left:-9999px; or something like it, so the label is still in the document (and still considered to be in the document) without bothering any users
same goes for the text on the button, don't remove it, just use text-indent:9999px; or something
Hi guys, I managed to
Hi guys,
I managed to customize/theme my search box the way I wanted using mytheme_search_theme_form() function in template.php + CSS
Now I try to create a different style/CSS for my search box on a different page using the same function...Is it possible? How can I override the search form id/class tags and use my own?
Thanks in advance