I'm totally stuck on this one. For my homepage, I've almost managed to create a great theme, but I'm stuck on the only thing left on my to-do-list.

The advanced search form. This is what I want to achieve:

• Remove the "first" submit button (the one in the basic search).
• Add an onclick="blah();" on the basic search text field.
• Add a

around the basic search part and a

around the other part, to be able to either show the basic or the advanced search, not both at the same time.
• Add a link in the advanced search part ("Basic search"), which while clicked, makes the advanced search form collapse and show the basic search form again.
• Change the "Advanced search" label/link thing a bit...

The presentation part, html/javascript/css, is no problem. But getting Drupal to change the advanced search thing seems too hard for me.

• The form can be hard-coded in php. There's no need for other dynamics than the adding/removing of taxonomies. My theme is not likely to show up on other sites in its present form.

What I've found out and tried:

I've found the search_view function (search.module), that calls the basic form, and node_form_alter (node.module), that adds the advanced search part to it. But I wasn't able to add a working theme_form_alter to my theme. Is that even possible?

I also tried to replace the $output = drupal_get_form('search_form', NULL, $keys, $type); line with a call to a theme function. I get the form exactly the way I want, but when searching, Drupal either just silently ignores the search and displays the form again, or whines about "Form validation failed".

Comments

augustekman’s picture

Ok, so after some work, I came up with this solution, with modified search.module and node.module.

In search.module I modified function search_form()

This:



  $form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Search'));

  return $form;

Into this:



  if ($type == 'node' && user_access('use advanced search')) {
  	$form['basic']['#prefix'] = '<div id="basic-search"><a href="' . $action . '" onclick="showAdvancedSearch(); return false;" class="search-switch">' . t('Advanced search') . '</a>';
  	$form['basic']['#suffix'] = '</div>';
  }
  else {
  	$form['basic']['inline']['submit'] = array('#type' => 'submit', '#value' => t('Search'));
  }

  return $form;

And in node.module I changed function node_form_alter():



$form['advanced'] = array(
    	'#prefix' => '<div id="advanced-search"><a href="/search/node" onclick="collapseAdvancedSearch(); return false;" class="search-switch">' . t('Basic search') . '</a><h2>' . t('Advanced search') . '</h2>',
    	'#suffix' => '</div>',
      //'#type' => 'fieldset',
      //'#title' => t('Advanced search'),
      //'#collapsible' => TRUE,
      //'#collapsed' => TRUE,
      //'#attributes' => array('id' => 'search-advanced'),
    );

There are javascript functions and styles as well, but I won't present them here for now.

Is it really not possible to alter a form from the template.php file instead of changing the drupal modules? (I tried but didn't get it to work)

coupet’s picture

AxelBernhardt’s picture

marthinal’s picture

Thanks i was searching for it.

The only source of knowledge is experience. ~ Albert Einstein.

pizangdesain’s picture

How to make some search criteria in advance search page?
like http://www.bekas.com/ads/search/adv
if we type keyword and select options all search result will match with search criteria...