Hey everyone, I was just wondering, is there a module that will let me edit the advanced search for my site to include extra fileds created with CCK?

Also - how do I add the link to 'advanced search' under the search box in the search block?

Comments

eviljoker7075’s picture

Is there nothing like this?

joel_guesclin’s picture

As I understand it there is no link between CCK and the standard site search, though I believe that it might be possible to write hooks for this (no idea exactly how though).

I think at the moment that the only way to do searches on CCK content is to use the Views module with selection criteria set to be entered at runtime.

eviljoker7075’s picture

Thanks, I think that is what I may have to do...

walkeroukor’s picture

Probably just be better to use the google site search thing

lebachai’s picture

I, too, searched for forums for the answer and found none, so I hacked (and I used this term heavily) a way to do this. I thought I'd share, with lots of disclaimers that I am not a PHP pro and have no idea how elegant this solution is (or more likely, not). But, it works.

You need two parts. Firstly, you have to create an anchor at the actual advanced search area on the search page. Here's how I did it. Open node.module and find this part:

<?php
// Advanced node search form
  elseif ($form_id == 'search_form' && arg(1) == 'node') {
    // Keyword boxes:
    $form['advanced'] = array(
      '#type' => 'fieldset',
      '#title' => t('Advanced search'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#attributes' => array('class' => 'search-advanced'),
    );
?>

You're going to replace this with a conditional statement to look at the incoming URL (we'll get to that in part 2) and to figure out if it should set an anchor or not. It is also going to tell it to display advanced search uncollapsed if the intent is to link directly to advanced search. Here's what you replace with:

<?php
// Advanced node search form
  elseif ($form_id == 'search_form' && arg(1) == 'node') {
      //CODE ADDED BY ME TO CREATE ADVANCED SEARCH LINK
	if($_GET['url'] =='advsearch'){
		// Keyword boxes:
   	      $form['advanced'] = array(
      	'#type' => 'fieldset',
      	'#title' => t('Advanced search<a name=advsearch></a>'),
      	'#collapsible' => TRUE,
     		'#collapsed' => FALSE,
     		'#attributes' => array('class' => 'search-advanced'),
    		);		
	}else{
    		// Keyword boxes:
    		$form['advanced'] = array(
    		'#type' => 'fieldset',
      	'#title' => t('Advanced search'),
      	'#collapsible' => TRUE,
      	'#collapsed' => TRUE,
      	'#attributes' => array('class' => 'search-advanced'),
    		);
	}	
?>

The only thing I could not figure out how to do is how to eliminate the second little black arrow that this will generate to collapse/uncollapse the advanced search area. It doesn't affect the functionality, so i decided to live with it...maybe somebody else can figure this one out? Ok, now part 2. Open template.php in your theme. We're going to add a function:

<?php
function phptemplate_search_block_form($form) {
  //need this first line to prevent breaking of existing CSS in my theme b/c form will not render with this 
 //div if this function is called
  $output = '<div class="container-inline">'.form_render($form['field_one']);
  $output .= form_render($form);
  $output .= "<br /><a href=\"index.php?q=search/node&url=advsearch\" title=\"Advanced Search\">advanced search</a></div>";
  return $output;
}
?>

This code renders the search form and adds the actual link underneath it. If your search block is called something else, replace "function phptemplate_search_block_form" with "function phptemplate_whatever_the_name_is." That's it. Hope this helps somebody.

Lebachai

zostay’s picture

I've done something similar to this, but I just added a custom Javascript file to my theme and then the link I needed. The Javascript contains:

function popOpenAdvancedSearch() {
    Drupal.toggleFieldset(".search-advanced");
}

if (window.location.hash == "#search-form") {
    $(document).ready(popOpenAdvancedSearch);
}

And then I just need to add a direct link to:

print l('Advanced Search', 'search/node', NULL, 'search-form');

That's good enough for me.

kingandy’s picture

The only thing I could not figure out how to do is how to eliminate the second little black arrow that this will generate to collapse/uncollapse the advanced search area.

The way to stop a fieldset being collapsible is to set '#collapsible' to FALSE (in the same place you're setting '#collapsed').

Seriously.

--Andy
Developing Drupal websites for Livelink New Media

++Andy

MauMau’s picture

The way to stop a fieldset being collapsible is to set '#collapsible' to FALSE (in the same place you're setting '#collapsed')

King Andy is right.
Changing anything in node.module is very wrong.
Using a link and a JavaScript to force open the advanced search is bad as well.

You should tell Drupal to keep it open at all times:

$form['advanced']['#collapsible'] = FALSE; //Will always display as decided in #collapsed
$form['advanced']['#collapsed'] = TRUE; //Will always display collapsed

Sadly I have no idea where this code should go to have an effect on the search/node-page.

Anyone?

MauMau’s picture

Put this in your template.php file

function phptemplate_search_form($form) {
// http://drupal.org/node/175013
$form['advanced']['#collapsible'] = FALSE; //Will always display as decided in #collapsed
$form['advanced']['#collapsed'] = TRUE; //Will always display collapsed
return drupal_render($form);
}

Another way to alter forms is to have a function like this:

function phptemplate_node_form($form) {
if ($form['type']['#value'] == 'story') {$form['scheduler_settings']['#collapsible'] = FALSE; $form['scheduler_settings']['#collapsed'] = TRUE; 
$form['scheduler_settings']['publish_on']['#value']= date(Y)  . "-" . date(m) . "-" . (date(d)+1) . " 00:00:01";
 }
}

This one will expand the form fields supplied by the scheduler module and suggest that the new story you are adding will debut 1 minute past midnight.

FWIW,
MauMau

garytiss’s picture

Thank you for your explanation, it helped me quite a bit.

starscream’s picture

Is there a way to do this correctly in Drupal 6 MauMau? I tried implementing this in template.php and then cleared the cache, but it didn't work.

function phptemplate_search_form($form) {
// http://drupal.org/node/175013
$form['advanced']['#collapsible'] = FALSE; //Will always display as decided in #collapsed
$form['advanced']['#collapsed'] = TRUE; //Will always display collapsed
return drupal_render($form);
}

Is there something I was doing wrong?

vm’s picture

I think drupal_render was changed in Drupal 6.x

wwam’s picture

Dear Lebachai,
I'm using drupal 4.7 and B7 theme.
In that case, the template.php that you mean is page.tpl.php file?
I found search_box function in other themes but not in my B7 theme.
Can you please help me where exactly should i put the above function that you suggest.
Thanks much in advanced for your great help.

jefke33’s picture

Template.php is a file that exists as well, and it is not the same as page.tpl.php. If it's not in your theme's folder, then I guess you can create it yourself with the said functions.
However, if your page.tpl.php doesn't have a searchbox, than I guess that no search box will show up on your pages anyway. So you will want to include the searchbox in your page.tpl.php. Probably the easiest way will be to copy the code that includes the search box from one of those other themes you mentioned.

Cheers,
Jefke

wwam’s picture

Thanks so much for your prompt reply.
I found template.php in other themes as you mentioned.
But in my theme B7 there is no template.php but search box is still on the front page.
I used B7 green theme.
Do you have and idea where I can I find that search box coding?

vm’s picture

For the B7 theme the searchbox is coded into page.tpl.php

dean.p’s picture

(Using Drupal 6.x)
I found this was a case of not seeing the forest for the trees. In my attempts to find a complicated answer for this, I found this easy solution that works.

Copy the search-block-form.tpl.php (from module/search) to your theme directory.

The file is pretty basic with the following code:

<div class="container-inline">
  <?php print $search_form; ?>
</div>

So I added in a line of code to get the following (wrapping the new link for easy theming):

<div class="container-inline">
<div class="advanced-search-link">
<a href="/search/node/" alt="Advanced search" >Advanced search &gt;&gt;</a>
</div>
  <?php print $search_form; ?>
</div>

And now I have a link in the search block that links straight to the advanced search page.

I don't think it is posssible however to add an argument to this link to auto-expand the 'advanced search' field group.

lilon’s picture

I did exactly as described:

1. copied the search-block-form.tpl.php (from module/search) to my theme directory (sites/all/theme).
2. dropped your code into the exact spot, as in your example above.
3. Saved the file.

Cannot see any difference.

4. flushed all chaches to be safe.

Still no change.

Any ideas?

lilon’s picture

forgot to mention, I use drupal 6.10

vm’s picture

try visiting administer -> themes to clear the theme registry.

lilon’s picture

I also went to administer > performance and cleared all chaced data, which didn't help either.

Anything else I can try?

usmccampbell’s picture

Are you trying to get the link to the Advanced Search? If so, do the following:

Go to /your/site/theme folder, and look for "page.tpl.php". Perform a search for if ($search_box), and you will see <?php print $search_box ?>. Replace that entire line with the following:

<?php if ($search_box): ?><div class="block block-theme"><?php print $search_box ?><br /><a href="/search/node">Advanced Search</a></div><?php endif; ?>

Save this, and then refresh your page.