Gossamer Forum
Home : Products : Links 2.0 : Discussions :

I'm having % replace all spaces in search field! HELP!

Quote Reply
I'm having % replace all spaces in search field! HELP!
I know that the % sign represents spaces but the CGI Script was supposed to change the % back to spaces.

In my search field, I type something in (lets say "dogs and cats") and hit "SEARCH". Then the results come back as:

Your search for "dogs%and%cats" was not found... instead of "Your search for dogs and cats was not found"

Can someone help? Tell me what files I need to edit etc.

Thanks,
Nichwatt
Quote Reply
Re: I'm having % replace all spaces in search field! HELP! In reply to
First of all, it isn't a % sign that represents the space, it is "%20" that does.

If you desire to display, in the search results, just "dogs and cats" instead of "dogs%20and%20cats", then use $query instead of $terms (or if using templates, use <%query%> instead of <%terms%> ).

I hope this helps.

[This message has been edited by Bobsie (edited May 29, 1999).]
Quote Reply
Re: I'm having % replace all spaces in search field! HELP! In reply to
Sorry about that, I meant that it displays %20 (replacing spaces).

I tried out the $query variable (replaced the $terms) and now it displays: Your search results for " " is 1 out of 1.

Between the parenthesis, there used to be "dogs%20and%20cats", now there is nothing. I'm thinking that $query may not be a valid variable.

Thank you for your time though-- help is still needed
Quote Reply
Re: I'm having % replace all spaces in search field! HELP! In reply to
Oops, try $in{'query'} instead of $query. That should work.
Quote Reply
Re: I'm having % replace all spaces in search field! HELP! In reply to
Right after I posted my 2nd message, I took a look at the perl script. I then used $in{'query'} (like you stated afterwards) and it still displays the same: Dogs%20and%20Cats

I then took another look at the script and found out that $term is the same thing as $in{'query'}. The $in{'query'} data is assigned to the $term variable.

Again, thank you for your help.
An answer is still needed. Btw- is anyone else having this same problem? When searching for something with spaces between, are the spaces showing up as %20?

Nichwatt
Quote Reply
Re: I'm having % replace all spaces in search field! HELP! In reply to
I have given you the answer. $in{'query'} is not the same as $term. In sub site_html_search_results of either site_html.pl or site_html_templates.pl, $term is defined as:

Quote:
my $term = &urlencode ($in{'query'});

The &urlencode call is what changes the spaces to %20. Before that call, $in{'query'} has no %20 in it and still does not after the call.

If you are getting the %20 when using $in{'query'}, then one of the following possibilities exist:

1. You haven't changed all the places where $term exisits when displaying the search results (you don't want to use $in{'query'} if not displaying the results).

2. Your page wasn't refreshed after changing to $in{'query'}.

3. Your script is broken.

$in{'query'} does not and can not use %20 for spaces as the script is written. If you are using templates, by the way, then you just use <%query%> in the template.

You can continue to say it doesn't work and keep asking for an answer. The answer I gave is the correct one. Of course, if you want to make $term useless for further searching, you can convert it back to truly match $in{'query'} by putting the following under the line I quoted above:

Quote:
$term =~ s/%20/ /g;

I hope this helps.

[This message has been edited by Bobsie (edited May 30, 1999).]
Quote Reply
Re: I'm having % replace all spaces in search field! HELP! In reply to
I found my error and apologize for the trouble and time I have wasted.

The problem was that I changed the Search Result section (in site_html.pl) to $in{'query'} and when I went to search, I used a different search term. When the search term was not found, the Error Page came up. I just remembered that I only changed the $in{'query'} in the Search Result page but not the Error Page Section.

Thank you for your time and help that you have given.

Again, sorry for the inconveniece is has caused.

Nichwatt
Quote Reply
Re: I'm having % replace all spaces in search field! HELP! In reply to
There's no need to apologize. These things happen to all of us. Glad you got it working.