You are here:  » Search through drop-down list integration...

Support Forum



Search through drop-down list integration...

Submitted by daem0n on Wed, 2009-05-27 06:34 in

Hi David,

Quick question. I've got your original drop-down search feature implemented with the following code:
(this code placed above header)

<?php
  
if ($_POST["action"] == "Search")
  {
    
$url "/".$_POST["category"]."/search.php?q=".$_POST["q"];
    
header("Location: ".$url);
    exit();
  }
?>

(this code placed in search area)
<?php
  
print "<form method='POST'>";
  print 
"<input type='text' name='q' />";
  print 
"<select name='category'>";
  print 
"<option value='cat1'>Category 1</option>";
  print 
"<option value='cat2'>Category 2</option>";
  print 
"</select>";
  print 
"<input type='submit' name='submit' value='Search' />";
  print 
"<input type='hidden' name='action' value='Search' />";
  print 
"</form>";
?>

The thing is, I'm trying to get the second part working with my site. I have it worked out to something similar to this:

<form id="SearchForm" method='POST' enctype="multipart/form-data">
<div>
<input type="text" class="input" name='q' id='q' size='35' />
<select name='category'>
<option value='cat1'>Category 1</option>
<option value='cat2'>Category 2</option>
</select>
<a href="#" class="search" onclick="document.getElementById('SearchForm').submit()"><span><span>Search</span></span></a>
</div>
<input type='hidden' name='action' value='Search' />
</form>

It works when I hit "enter" after putting in my search terms but still doesn't work when I click on the "Search" button. Any idea what I'm doing wrong?

Thanks a lot! -Joe

Submitted by support on Wed, 2009-05-27 08:16

Hi Joe,

I just tried your exact code on my test server and it worked fine - so i'm wondering if perhaps there is something else on your page with the id of SearchForm? The Firefox Error Console (Tools menu) is good for debugging this sort of thing.

Visit the page, open the Error Console and first clear all entries. Then click your link and it should indicate the problem....

Cheers,
David.

Submitted by daem0n on Thu, 2009-05-28 04:59

Hi David,

Thanks a lot for your reply. I guess sometimes it helps to have someone with a clear head looking at your code :P. You were right, I had the same id right above it because I left the old code in while I was testing the new code (not the best idea in this case).

Thanks for the help and the debug tip!!

-Joe