Print a form, such as a search form, anywhere in Drupal
Resolved error:
Missing argument 1 for search_box(), called in /sites/example/www/includes/common.inc(1352) : eval()'d code on line 5 and defined in /sites/example/www/modules/search/search.module on line 1037.
This was from code added to a page's content by a client or possibly even the previous developer. We completely redid the site but did copy-paste in some pages.
I'd like to just print the form, so go looking for a search form function... ah! http://api.drupal.org/api/function/search_form/5 Who would have thought it.
As shown in the screen shot, this code in a node (or block) with PHP enabled under "Input format" should work beautifully:
<div class="searchblock">
<?php
print drupal_get_form('search_form');
?>
</div>
This is the same approach used in:
Display a Drupal login form anywhere with PHP, including in page content
Postscipt: Looking at search_box() --
http://api.drupal.org/api/function/search_box/5
<?php
function search_box($form_id) {
// Use search_keys instead of keys to avoid ID conflicts with the search block.
$form[$form_id .'_keys'] = array(
'#type' => 'textfield',
'#size' => 15,
'#default_value' => '',
'#attributes' => array('title' => t('Enter the terms you wish to search for.')),
);
$form['submit'] = array('#type' => 'submit', '#value' => t('Search'));
$form['#base'] = 'search_box_form';
return $form;
}
?>
-- it seems that with any made-up form id it would work?
Comments
Post new comment