Advanced Search.. really that advanced!?

eviljoker7075 - September 25, 2006 - 21:01

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?

Is there nothing like this?

eviljoker7075 - September 26, 2006 - 22:08

Is there nothing like this?

No link between Search and CCK

joel_guesclin - September 28, 2006 - 11:57

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.

Thanks, I think that is what

eviljoker7075 - September 28, 2006 - 20:38

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

Probably just be better to

walkeroukor - February 2, 2009 - 23:17

Probably just be better to use the google site search thing

Here's how I linked directly to advanced search

lebachai - December 20, 2006 - 14:02

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

Using Javascript instead of PHP hacks to link

zostay - June 28, 2007 - 22:32

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:

<?php
print l('Advanced Search', 'search/node', NULL, 'search-form');
?>

That's good enough for me.

You'll kick yourself ...

kingandy - January 30, 2008 - 11:47

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

When the right solution is hard

MauMau - February 11, 2008 - 12:12

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?

How to collapse fields

MauMau - February 11, 2008 - 13:16

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

Thank you for your

garytiss - March 27, 2008 - 20:58

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

Is there a way..

starscream - October 7, 2008 - 00:18

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?

=-=

VeryMisunderstood - October 7, 2008 - 04:11

I think drupal_render was changed in Drupal 6.x

Dear Lebachai, I'm

wwam - May 8, 2008 - 08:05

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.

template.php

jefke33 - May 8, 2008 - 12:28

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

Thanks so much for your

wwam - May 9, 2008 - 02:54

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?

=-=

VeryMisunderstood - May 9, 2008 - 03:29

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

Easy way add the link to 'advanced search' under the search box

_Sack_ - March 17, 2009 - 21:06

(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.

doesn't work for me

lilon - March 25, 2009 - 05:39

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?

forgot to mention, I use

lilon - March 25, 2009 - 05:40

forgot to mention, I use drupal 6.10

=-=

VeryMisunderstood - March 25, 2009 - 12:51

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

didnt help

lilon - March 30, 2009 - 02:02

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

Anything else I can try?

 
 

Drupal is a registered trademark of Dries Buytaert.