You are here:  » Search form


Search form

Submitted by IG on Tue, 2012-04-17 12:03 in

Hi David!

I would like the search form of the Pricetapestry.org search widget to look like the search form of the search widget of the theme. You can see both of them {link saved}, the first one being the search form of the search widget of the theme.

How would you go about this? Give the Pricetapestry.org search widget the look of the search form of the theme? Where and how? Or give the search form of the theme the functionality of the Pricetapestry.org search form? Where and how?

I look forward to your guidance.

Cheers, IG

Submitted by support on Tue, 2012-04-17 14:10

Hello IG,

It looks like your theme's search widget is styled by id='searchform' and the search box itself id='s' so first you would need to duplicate these in your WordPress theme using a different name, for example

searchform_pto
s_pto

That that in place, try the following as a replacement for the Search Widget HTML module in wp-admin > Settings > PriceTapestry.org:

<div class='pto_search_widget'>
<form method='GET' id='searchform_pto' action='%ACTION%'>
<fieldset>
<input type="text" name="pto_q" id="s_pto" value="To search type and hit enter" onfocus="if(this.value=='To search type and hit enter')this.value='';" onblur="if(this.value=='')this.value='To search type and hit enter';" />
</fieldset>
<noscript>
<input type='submit' value='Search' />
</noscript>
</form>
</div>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Wed, 2012-04-18 11:21

Thanks a lot David! Works like a charm.

Submitted by IG on Wed, 2012-05-02 20:04

Dear David

Another problem has come up and I have to pick your brain again. I am using the following search form on the A-Z pages:

<div class='pto_search_widget'>
<form method='GET' id='searchform_pto' action='/produkte'>
<fieldset>
<input type="text" name="pto_q" id="s_pto" value="Produktsuche und Preisvergleich..." onfocus="if(this.value=='Produktsuche und Preisvergleich...')this.value='';" onblur="if(this.value=='')this.value='Produktsuche und Preisvergleich...';" />
</fieldset>
<noscript>
<input type='submit' value='Search' />
</noscript>
</form>
</div>

How do I need to modify the above code to search only within the products of a particular merchant (after clicking on a merchant on A-Z merchants) or only within a particular category (after clicking on a category on A-Z categories). Currently, after clicking on a particular merchant or category, the whole database is searched.

Submitted by support on Thu, 2012-05-03 09:13

Hi,

You will need the Exec PHP plugin, and then you can add the following code to your form (add before the closing </form> tag)

<?php
if (isset($pto_q))
{
  
$parts explode(":",$pto_q);
  switch(
$parts[0])
  {
    case 
"merchant":
      print 
"<input type='hidden' name='pto_merchantFilter' value='".htmlentities($parts[1])."' />";
      break;
    case 
"category":
      print 
"<input type='hidden' name='pto_categoryFilter' value='".htmlentities($parts[1])."' />";
      break;
  }
}
?>

(you could add a case for brand as well of course...)

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Thu, 2012-05-03 10:09

Hi David

I have installed Exec PHP plugin and copied the above code before the closing tag. Unfortunately, no luck so far as you can see: {link saved}

It seems to me that wordpress somehow has a problem how the code is formatted. For example, if I post the first two lines as one line like this [<?php if (isset($pto_q))], then [if (isset($pto_q))] is no longer shown when I call {link saved}. However, I did not succeed to reformat the text completely and wonder if you can help?

Best regards,
Ivo

Submitted by support on Thu, 2012-05-03 10:31

Hello Ivo,

I checked the code syntax and all looks fine; however when I view the source of your page the PHP code is being formatted. When editing your post in wp-admin, make sure that you use the editor in "HTML" mode so that the PHP is inserted "as-is". PHP code can normally be inserted via the HTML tab but you may need to temporary disable your WYSIWYG editor which you can do from your admin user profile page...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Thu, 2012-05-03 11:30

Hi David

I'm trying to insert this code under Settings > PriceTapestry.org > A-Z > Before All

I have managed to remove all the line breaks, but still some formatting remains: {link saved}

I tried to enter the code directly with phpMyAdmin, but when I save the code it is also reformatted. I guess there must be a way to save the code without any changes, if I only would know how?

I'm sorry for the trouble...

Cheers, Ivo

Submitted by support on Thu, 2012-05-03 11:51

Hello Ivo,

Ah my apologies I thought this was part of a manually created search form.

No problem; ignore the above i'm afraid, and instead of adding anything within the PriceTapestry.org templates it can be done with a small modification to pto_search.php.

In that file, look for the following code at line 33, within the pto_search_form() function:

  return $html;

...and REPLACE that with:

  $filters = "";
  $parts = explode(":",$pto_q);
  switch($parts[0])
  {
    case "merchant":
      $filters .= "<input type='hidden' name='pto_merchantFilter' value='".htmlentities($parts[1])."' />";
      break;
    case "category":
      $filters .= "<input type='hidden' name='pto_categoryFilter' value='".htmlentities($parts[1])."' />";
      break;
  }
  $html = str_replace("</form>",$filters."</form>",$html);
  return $html;

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Thu, 2012-05-03 13:24

Hi David

The above worked - thank you. However, I have second thoughts as it won't show the merchant or category in the search field. Having changed the search form value back to %PTO_Q% I wonder why it doesn't deliver any results. For example, if I search for "bettinhalt" on {link saved} there are no results, despite the fact that there is a product. Any idea why that would be?

And one last question (hopefully). Which files do I need to change in order to replace "merchant:" and "category:" with a different word in search and in titles?

Thanks a million for your support!
Ivo

Submitted by IG on Thu, 2012-05-03 13:54

Hi David

I had a look at the demo and it seems to me that the demo has the same problem. Please go to this page http://wordpress.webpricecheck.co.uk/merchant/Direct-TVs and search for "acer", by clicking in the search field and adding "acer" to "merchant:Direct TVs:" so that it will read "merchant:Direct TVs:acer" before you click to search. The message says "Sorry, there are no results to display." despite the fact that this merchant has several acer products. Is this meant to be like this or a bug?

Cheers, Ivo

Submitted by support on Thu, 2012-05-03 14:02

Hello Ivo,

The search code isn't actually set-up to handle that but it's an easy modification.

In pto_search.php, look for the following code at line 193:

  $where .= " ".$field." = '".$wpdb->escape($parts[$i])."' ";

...and REPLACE with:

  if ($field)
  {
    $where .= " ".$field." = '".$wpdb->escape($parts[$i])."' ";
  }
  else
  {
    $where .= " name LIKE '%".$wpdb->escape($parts[$i])."%' ";
  }
  $field = "";

To replace merchant:, category: and brand: with alternative text in the page title, look for the following code at line 431 of pto.php:

    $title = htmlentities($pto_q,ENT_QUOTES,get_settings("blog_charset"));

...and REPLACE with:

    $title_q = $pto_q;
    $title_q = str_replace("merchant:","Merchant Alternative ",$title_q);
    $title_q = str_replace("category:","Category Alternative ",$title_q);
    $title_q = str_replace("brand:","Brand Alternative ",$title_q);
    $title_q = str_replace(":"," ",$title_q);
    $title = htmlentities($pto_q,ENT_QUOTES,get_settings("blog_charset"));

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Thu, 2012-05-03 15:12

Hi again!

The search part worked - thanks a lot.

The code to replace merchant:, category: and brand: had unfortunately not the desired result as you can see here: {link saved}. The title still shows "merchant:" in the title and also in the search field itself.

Cheers, Ivo

Submitted by support on Thu, 2012-05-03 15:21

Sorry Ivo, having made all the changes to $title_q I forget to update the variable in the actual line that sets the title! Have a go with:

    $title_q = $pto_q;
    $title_q = str_replace("merchant:","Merchant Alternative ",$title_q);
    $title_q = str_replace("category:","Category Alternative ",$title_q);
    $title_q = str_replace("brand:","Brand Alternative ",$title_q);
    $title_q = str_replace(":"," ",$title_q);
    $title = htmlentities($title_q,ENT_QUOTES,get_settings("blog_charset"));

(it's just the last line that's changed)

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Thu, 2012-05-03 15:47

Looking great now - thanks!

Another thing which I'm very keen to change is merchant:, category: and brand: in the search field. You have helped me to do that ages ago in the standalone version and therefore I can't remember which files require changes.

Once again a big THANK YOU David.

Cheers, Ivo