Sorry. Was in bit of a hurry last time.
So, below would be FORM.PHP or whatever you want to call your forms page. Here it is in more detail. It assumes we're just checking for a name and email address.
<?php
$error = true;
if ((isset($_POST['action'])) && ($_POST['action'] == 1))
{
// check other posted variables
// if everything is what you wanted
// cleanse the data and write it to a DB or something
// set $error to false if everything is successful
if (!$error)
{
header("location: thankyou.php");
exit;
}
}
?>
<html>
<head>
<title>My Form</title>
</head>
<form method="post" action="form.php">
<!-- set the test variable to 1 //-->
<input type="hidden" name="action" value="1" />
Name: <input type="text" name="name" value="<?php if(isset($_POST['name'])) echo $_POST['name']; ?>"><br/>
Email: <input type="text" name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>"><br/>
<input type="submit" name="submit" value=" Submit " />
</form>
</html>
The first time you run the script, there will not be a $_POST['action'] form param set yet so it will simply show the form. And since there will be no values for the form elements, those will just have empty values.
Once the user submits the form, the action param gets set and you will need to do some error checking on your side. If the error checking is successful, just set $error to false and it will do the redirect after you were done. Otherwise, it will show the form again and populate it with whatever was originally entered. You'd have to write some loops to populate HTML form selects if you have any.
Disregard my mention of echoing the form. You could either use it as it or put the form into a separate file in which case you would include() it -- that's how I usually do things.
Hope that makes it clearer.
Best,
Cent.