Link to home
Start Free TrialLog in
Avatar of toymachiner62
toymachiner62Flag for United States of America

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';
			}
		}

Open in new window

Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

empty(0) returns true USE isset instead

empty() reference:
http://us2.php.net/empty 
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(isset($_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';
                        }
                }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of NerdsOfTech
NerdsOfTech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toymachiner62

ASKER

is_null() works great. Thanks