User login

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?

Resolution

Searched words: 
form anywhere print form print search form drupal print the searchform

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.