I am doing a test validation form, I am not getting the error message to display;
here is the code:
<?php
#-----CHECK SUBMITTION ----------
if (isset($_POST['action']) || ($_POST['action'] == 'submitted'))
{
#-----CHECK IF NAME FIELD IS EMPTY----
if (empty($_POST['name']))
{
$message = "* Name is required";//exit;
}
#-------CHECK IF AGE IS AN INTEGER AND EMPTY----
if( (empty($_POST['age'])) && (!is_int($_POST['age'])) )
{
$message = "* Age is required";
exit;
}
echo '<pre>';
print "Name: ";
echo $_POST['name'];
echo '<br>';
print "Age: ";
echo $_POST['age'];
echo '</pre>';
echo '<a href="'. $_SERVER['PHP_SELF'] .'">Back</a>';
echo '</pre>';
} else {
//ERROR MESSAGE ($message) IS DISPLAYED BESIDE EACH FIELD IF RESULT IS TRUE//
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Your name: <input type="text" name="name" > <?php echo $message; ?></label><br />
<label>Your age: <input type="text" name="age" ><?php echo $message; ?> </label><br />
<input type="hidden" name="action" value="submitted">
<label><input type="submit" ></label>
</form>
<?php
}
?>