Custom Search Form not working properly

I am not using the `printSearchForm()`function, instead I have a custom search form which replicates the basic zenphoto search form plus I have added a series of checkboxes for common tag values.

I am searching on titles and partial tags only.

The form has an `onSubmit` event which fires a javascript which concatenates the contents of the input textbox `id="search_input` with the values of the checkboxes which I get using MooTools functions.
I then set the search input textbox to this new string and submit the forming using `sf.submit`, where `sf` is the form object.

However my search string is getting truncated somewhere along the line. If I type `tree` in the search box and check `photo` I generate the search string `treeANDphoto`. The search seems to lose my constructed string and only operates with what's in the inputbox ie `tree`.

Perhaps I'm being too clever for my own good when I guess I don't really understand the subtleties of how search works. Can you give me some advice and perhaps point me at some documentation about how search works. I've scanned the `class-search` code, and it's a bit above my level of PHP expertise - should I be using the `setSearchParams` function directly ...?

Comments

  • Meant to say I'm using v1.2.5
  • It would sound like your custom code is not submitting the full search string that you desire. The search engine will parse the `$_REQUEST['words']` parameter for the search search criteria. This is what you have to populate with your javascript onSubmit.

    For more details look at the class-search instantiation function.
  • I seem to be submitting the search string. If I `echo $_POST['words']` I see the full search string `tree&photo` but when I `echo $_REQUEST['words']` I get just `tree`
  • Interesting. Those two should be the same. Of course, I do not know what the JS interaction might be doing. Anyway, you need to get the `$_REQUEST['words']` bit correct as that is what the search engine looks at. One way to do that would be to add it to the query parameter string.
  • Had another thought. Perhpas it is the '&' character that is causing you the trouble. Have you tried using `AND` instead? Remember, ofthe & is used as a separator on WEB URLs. In those cases you have to use the HTML entity `&` in its place. This is different for POST methods from GET methods. Perhaps the Javascript is not properly dealing with this.
  • I did a `print_r` on both of the `$_POST` and `$_REQUEST` arrays and the answer was obvious.

    It was my bad.

    I use `document.cookies` to persist the form settings and the one that held the value of the search box was called `words` too. I had forgotten that `$_REQUEST` retrieves `$_GET` and `cookie` values too and `$_REQUEST` was picking up the cookie.

    Thanks for your time and apologies for my stupidity!
Sign In or Register to comment.