[thelist] Form Field Validation (mySQL / PHP)?
Jay Greenspan
jay at trans-city.com
Mon Jan 22 16:46:31 CST 2001
> $goodInput = false;
> if (IsSet($last_name)) $goodInput = true;
> if (IsSet($first_name)) $goodInput = true;
> if (IsSet($dept)) $goodInput = true;
> if (IsSet($title)) $goodInput = true;
> if (IsSet($phone)) $goodInput = true;
> if (IsSet($email)) $goodInput = true;
>
> Then, just do something if $goodInput is still false after the above code
> segment.
>
> I'm generally against accessing form values like this, but off-hand, I'm not
> sure whether the following would always report as true or not:
>
> if (IsSet($HTTP_POST_VARS['last_name'])) ...
I think !empty() would work (assuming that zero is not a valid search
criterion).
you could put it in a function, though it might be overkill...
function is_one_not_empty($array)
{
global $HTTP_POST_VARS;
while(list( , $value) = each($array))
{
if(!empty($HTTP_POST_VARS[$value])
{
return TRUE;
}
}
return FALSE;
}
$valid_fields = array("fname", "lname", "phone");
if(is_one_not_empty($valid_fields))
{
//process form
} else
{
//dont process form
}
if it's just a few of them, probably better off with Matt's way or
if(!empty($field_1) && !empty($field_2) && !empty(field_3))
{
}
-j
More information about the thelist
mailing list