You are here:  » searchform.php

Support Forum



searchform.php

Submitted by philstone on Sat, 2006-10-14 09:50 in

Hi Dave

Is there a simple way to add a drop down box to the whole site that has a merchant dropdown box between the search query and search button?

was wondering if the box would autofill with registered merchants?

Regards

Phil

Submitted by support on Sun, 2006-10-15 08:54

Hi Phil,

This is actually a tad trickier than it sounds because to do this you have to provide an additional parameter to search.php - and that parameter then has to be persisted into all the follow on links to change the sort order or navigate between pages. However, first things first it needs a new searchform.php to create the merchant box:

html/searchform.php

<?php
  
print "<div class='searchform'>";
  print 
"<form name='search' action='".$config_baseHREF."search.php'>";
  print 
"<input type='text' name='q' size='25' value='".(isset($q)?$q:"")."' />";
  
$sql "SELECT * FROM feeds ORDER BY merchant";
  if (
database_querySelect($sql,$feeds))
  {
    print 
"<select name='m'>";
    print 
"<option value=''>All Stores</option>";
    foreach(
$feeds as $feed)
    {
      print 
"<option value='".$feed["merchant"]."' ".($m==$feed["merchant"]?"selected='selected'":"").">".$feed["merchant"]."</option>";
    }
    print 
"</select>";
  }
  print 
"&nbsp;<input type='submit' value='".translate("Search")."' />";
  print 
"</form>";
  print 
"</div>";
?>

Next, changes must be made to search.php to check for the "m" parameter on the URL. Look for the following code on line 3:

$q = (isset($_GET["q"])?tapestry_normalise($_GET["q"],":\."):"");

...and add the following code immediate afterwards:

$m = (isset($_GET["m"])?$_GET["m"]:"");

Then, lower down the script look for the following code on line 34:

    $parts = explode(":",$q);

and REPLACE that with the following:

    if ($m)
    {
      $parts[0] = "merchant";
      $parts[1] = $m;
      $parts[2] = $q;
    }
    else
    {
      $parts = explode(":",$q);
    }

That's the basic functionality sorted. Next, look for the following line of code that constructs the base URL used in the change sort order links (approx line 111):

$sortHREF = $config_baseHREF."search.php?q=".urlencode($q)."&amp;page=1&amp;sort=";

...and change it to this:

$sortHREF = $config_baseHREF."search.php?q=".urlencode($q)."&amp;m=".urlencode($m)."&amp;page=1&amp;sort=";

Finally, in html/navigation.php, do a SEARCH and REPLACE as follows:

SEARCH:

"?q=".urlencode($q)."

REPLACE:
"?q=".urlencode($q)."&amp;m=".urlencode($m)."

Hope this helps,
Cheers,
David.

Submitted by philstone on Mon, 2006-10-16 09:12

Works a treat

thanks

Submitted by James Warren on Wed, 2006-10-25 14:47

Hi I am beginning to be a pain!
I just went through this mod and it works great, but, i can only display the first 10 products. I have lost the "Next Page".
http://www.thehighstreetonline.com

Thanks
James Warren

Submitted by support on Wed, 2006-10-25 15:17

Hi James,

Has the entire navigation bar disappeared - page 1,2,3 etc.?

Submitted by support on Wed, 2006-10-25 15:39

Hi Again,

I noticed that your HTML is finishing at the end of the last product on the page - there is no navigation HTML or the end of page HTML, so the most likely cause is a change in navigation.php has caused a PHP error but this is not being displayed because your server has error display turned off.

Double check your changes in html/navigation.php - send me your modified version by email if in doubt (reply to your reg code or forum reg email) and i'll take a look...

Cheers,
David.