5

I've using Views and Page Manager to create a custom search results page. You can see it here:

http://quotefail.com/search/node/world

The page is being generated by Page Manager. I've got a Search Form in the top panel, but it starts empty. I'd like it to be pre-filled with the search term that was used to generate this page.

How can I prepopulate the search form with that search term?

Here is my page config:

enter image description here

Here is my Search View in the center panel:

enter image description here

  • Upvote for relevant screenshots. – beth Aug 11 '12 at 20:39
3

Looks like from that link that the search form is the search block form, so you can do this as a theme form alter (you could also make a custom module in a similar fashion with form alters but this should serve your needs). This goes in your template.php for your theme:

function YOURTHEMENAME_form_alter(&$form, &$form_state, $form_id) {
  switch ($form_id) {
    case 'search_block_form':
      //checking if arg(2) exists so it doesn't try to do this if some visits the search page straight away
      if(arg(2)){ 
        $form['search_block_form']['#default_value'] = arg(2);
      }
      break; 
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.