I have this basic form, found at http://www.bufftec.com/orginal.php When you populate the form and click submit it takes you to a new page and displays your information. What i cant figure out is when some doesnt fill out the information in the form and clicks submit it still goes to the page and displays nothing. What i need it to do is to when the user clicks submit, if the form is empty, the resulting effect is the form just displayed again rather then going to the blank page. I have tried all sorts of IF ELSE and just cant get it to work. Below is the full code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Form</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<p>Please Enter the Requested Information</p>
<br />
<?php
if (isset($GET['contact'])){
$firstname = (isset($GET['firstname'])) ? htmlspecialchars($GET['firstname'], ENT_QUOTES) : '';
$lastname = (isset($GET['lastname'])) ? htmlspecialchars($GET['lastname'], ENT_QUOTES) : '';
$street = (isset($GET['street'])) ? htmlspecialchars($GET['street'], ENT_QUOTES) : '';
$city = (isset($GET['city'])) ? htmlspecialchars($GET['city'], ENT_QUOTES) : '';
$state = (isset($GET['state'])) ? htmlspecialchars($GET['state'], ENT_QUOTES) : '';
$zip = (isset($GET['zip'])) ? htmlspecialchars($_GET['zip'], ENT_QUOTES) : '';
echo "<p> Here is the information you have entered. You entered: </p><p> $firstname $lastname </p> <p> $street </p> <p> $city , $state $zip </p>";
} else { ?>
<form name="contact" id="contact" method="get" action="<?php if ($firstname != '' ) { echo $_SERVER['PHP_SELF']. '#form';}?>">
<p><label>First Name
<input name="firstname" type="text" id="firstname" value="<?php echo $firstname; ?>" />
</label></p>
<p><label>Last Name
<input name="lastname" type="text" id="lastname" value="<?php echo $lastname; ?>" />
</label></p>
<p><label>Street
<input name="street" type="text" id="street" value="<?php echo $street; ?>" />
</label></p>
<p><label>City
<input name="city" type="text" id="city" value="<?php echo $city; ?>" />
</label></p>
<p><label>State
<input name="state" type="text" id="state" value="<?php echo $state; ?>" />
</label></p>
<p><label>Zip Code
<input name="zip" type="text" id="zip" value="<?php echo $zip; ?>" />
</label></p>
<input name="contact" type="submit" value="submit" />
</form>
<?php } ?>
<?php
if(empty($firstname['PHP_SELF'])){ echo 'All Fields Are Required'; }
else { echo 'Thank You For Your Submission';}
?>
</body>
</html>