Welcome! Log In Create A New Profile

Advanced

Avoid no keyword submit...anyone please help

Posted by hawkeye 
Avoid no keyword submit...anyone please help
September 26, 2007 04:12AM
Hello;

Is there anyway to avoid submit no keyword to the search form? I see that even there is no keyword; but if you just press Search it still go and search (of course there is no results). Or when the users access direct to localhost/sphider/search.php?q=&search=1 it also shows there is no results.

So how can avoid this please? Cause it could save some bandwith too.... Like if there is no keywords or access to url search without any keywords then it just redirect you to search.php.

Thank you
Tec
Re: Avoid no keyword submit...anyone please help
September 26, 2007 11:51AM
Hello hawkeye.

In search.php search for:

$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html"winking smiley;
break;

Delete these three rows and replace them with the following:

if($query !=''){;
$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html"winking smiley;
break;
}


Happy coding

Tec
Re: Avoid no keyword submit...anyone please help
September 26, 2007 12:00PM
thanks a lot....it works great
Re: Avoid no keyword submit...anyone please help
September 26, 2007 02:08PM
Hello; sorry to bother you again. I just want to ask; I have added this

if($query !=''){;
$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html"winking smiley;
break;
}

i want also if there is a space but no keywords in the search so it also do the same. I have tried

if($query !=''){;
$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html"winking smiley;
break;
}elseif($query !=' '){;
$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html"winking smiley;
break;
}

but it doesnt work...what should i do?

Thank you
Tec
Re: Avoid no keyword submit...anyone please help
September 26, 2007 04:24PM
if($query !=''){;
if($query !=' '){;
$search_results = get_search_results($query, $start, $category, $type, $results, $domain);
require("$template_dir/$template/search_results.html"winking smiley;
break;
}
}


Tec
Re: Avoid no keyword submit...anyone please help
September 26, 2007 05:50PM
very cool, thank you!
Re: Avoid no keyword submit...anyone please help
September 27, 2007 12:21AM
Something that may work also and be a little cleaner

IF ( !EMPTY( TRIM( $query ) ) ) {
$search_results = get_search_results($query, $start, $category,
$type, $results, $domain );
require("$template_dir/$template/search_results.html"winking smiley;
}

remove the periods
Tec
Re: Avoid no keyword submit...anyone please help
September 27, 2007 11:42PM
Did you check your snippet before publishing here?

My result:
Fatal error: Can't use function return value in write context in C:\Programme\xampp\htdocs\...\sphider\search.php on line 130

Line 130: IF ( !EMPTY( TRIM ($query )) ) {

Reason: empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($query)).

Tec
Re: Avoid no keyword submit...anyone please help
September 28, 2007 01:04AM
rr1024

You were fishing answers?
Re: Avoid no keyword submit...anyone please help
September 28, 2007 01:37AM
my bad...sorry didn't test it
FIND
if (isset($_GET['query']))
$query = $_GET['query'];
REPLACE WITH
if (isset($_GET['query']))
$query = TRIM( $_GET['query'] );

Here you may consider triming all your $_GET vars....up to you of course

Then do
IF ( !EMPTY( $query ) ) {
$search_results = get_search_results($query, $start, $category,
$type, $results, $domain );
require("$template_dir/$template/search_results.html"winking smiley;
}

I'm not sure what you mean by fishing answers? do you mean fishing for answers...then no I wasn't
Re: Avoid no keyword submit...anyone please help
September 28, 2007 10:11AM
Thanks, rr1024
Re: Avoid no keyword submit...anyone please help
September 28, 2007 03:31PM
To the atention of Ando:

In my experience, the first part of rr1024's code seems enough to correct the bug reported by hawkeye. So:

In search.php search for

if (isset($_GET['query']))
$query = $_GET['query'];
REPLACE WITH
if (isset($_GET['query']))
$query = TRIM( $_GET['query'] );
Re: Avoid no keyword submit...anyone please help
September 29, 2007 06:39PM
thank you very much
Sorry, only registered users may post in this forum.

Click here to login