0

I created view & content pane that has many filters and also search term field. In addition, I created a page with page manager and panels, that present this search view (content pane), with more different panels.

My goal is to have search field, on the header of the site, that will be available to user in any time. when the user will decide to use this search field, it will direct them to the search page I created (using page manger & panels), and will show the search results on this specific page.

Can I do that? If so, can you please explain me how?

I read on how to that using views alone, but I couldn't understand how to that with the use of page manager and panels all together.

Thanks.

2 Answers 2

1

If I understand the question correctly, you would like to send users from a search form to a specific (custom) search results page (which happens to also have some other panels etc on it).

I do not believe the panels/page manager aspect really affects how the search box operates, in which case all we have to do is specify where you would like the search form to send the user.

The following code (for an imaginary module entitled customsearch just found existing module entitled custom_search, not related).

  1. creates a block to hold a search form (you can then place this wherever you want)
  2. constructs a simple textfield search form to go in the block
  3. defines a custom submit to pass the search argument to your customised search results page

1)

// Implements hook_block_view().
function customsearch_block_view($delta = '') {
  if (user_access('search content')) {
    $block['content'] = drupal_get_form('customsearch_block_form');
    return $block;
  }
}

2)

// Implements hook_forms().
function customsearch_forms() {
  $forms['customsearch_block_form']= array(
    'callback' => 'customsearch_box',
    'callback arguments' => array('customsearch_block_form'),
  );
  return $forms;
}

// Form builder; Output a search form for the search block's search box.
function customsearch_box($form, &$form_state, $form_id) {
  $form['customsearch_form'] = array(
    '#type' => 'textfield',
    '#title' => '',
    '#title_display' => 'invisible',
    '#default_value' => '',
    '#attributes' => array(
      'title' => t('Search the website'), 
      'placeholder' => t('search the website'),
    ),
  );
  $form['actions'] = array('#type' => 'actions');
  $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Search'));

  // define function to determine search destination
  $form['#submit'] = array('customsearch_search_box_form_submit');

  return $form;
}

3)

// overide submission of search query from block
function customsearch_search_box_form_submit($form, &$form_state) {
  $searchterm = $form_state['values']['plus_search_form'];
  $search_path = 'specialcustomsearch'// replace with the path to your search results page
  // pass search term to your search results page as argument
  drupal_goto($searchpath .'/'. $searchterm);
}
1

Unless there is a special need, you won't have to add any custom coding. It's even possible to use the standard Drupal search block. If you are using Panels to build your site, you can place it in the header region in the Panels interface, and use CSS to style it.

One caveat, though (I've learned this through experience)--some content displayed in Panels that isn't part of the Node Content may not be properly indexed if not set up correctly. It may be good to reference this other article.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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