The code from cgraz doesn't work because it just checks if the variable is set and not, if it is empty!
This is a whole example:
Make sure that you write the name of your RESULT file as the action value! Otherwise it doesn't work!
And here comes the content of your result.php file (or however you want to call it, but take the name you have in your form-tag!
<?
if ( strlen($name_of_field1)==0 || strlen($name_of_field2)==0 || strlen($name_of_field3)==0 )
// you can add more fields just by copypaste the code. Seperate the conditions by '||'
{
// None of the fields contained a value!
echo "You must fill in at least one field";
}
else
{
// User filled out at least one field (but you don't know which one)
echo "You filled out at least one field!";
}
?>
You can even combine the search form and the result page in one script, e.g. 'search.php'
<?
// Assume that results will not be displayed:
$showed_result = false;
// Check if user has submitted the form:
if (!( strlen($name_of_field1)==0 || strlen($name_of_field2)==0 || strlen($name_of_field3)==0 ))
// you can add more fields just by copypaste the code. Seperate the conditions by '||'
// See the difference of the ! to the script written above!
{
// User filled out at least one field (but you don't know which one)
echo "You filled out at least one field!";
// here you perform your search!
// make sure to set the following row, if you display the results:
$showed_results = true;
// If you don't write this line, the search form will be displayed!
}
// Show the form to search:
if( !$showed_results )
{
?>
<form action="<? echo $PHP_SELF; ?>" target="_self" method="post">
<!-- your form fields comes here -->
</form>
<?
}
?>
hth
getting_stupid_but_still_willing_to_help