toymachiner62
asked on
Trying to validate a form with the number 0
I have a form and a validation script to insert the data. I want to allow the user to enter the values 0,1,2, or 3. If a user enters 0 as a value, they get an error that nothing has been entered. How do i allow 0's to be entered?
Sample of the form
<li>
<label for="WoodFrog">Wood Frog</label>
<input name="WoodFrog" type="text" value="<?php if(isset($_POST['WoodFrog'])); ?>" />
</li>
sample of the validation script
if(empty($_POST['WoodFrog']))
{
$errors[] = 'You forgot to enter the number of Wood Frogs.';
}
else
{
if($_POST['WoodFrog'] == 0 OR $_POST['WoodFrog'] == 1 OR $_POST['WoodFrog'] == 2 OR $_POST['WoodFrog'] == 3)
{
$woodFrog = trim($_POST['WoodFrog']);
}
else
{
$errors[] = 'You entered an invalid number for Wood Frog';
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
is_null() works great. Thanks
empty() reference:
http://us2.php.net/empty
Open in new window