The form should POST data back to itself (using $PHP_SELF).
The script should start with some logic like this:
if ($REQUEST_METHOD == 'POST')
{
// you're getting the form data, do something with it
}
else
{
// generate the form
}
A slightly better variant of this, if you have to do a lot of form validation, is:
function generate_form( ... parameters here...)
{
global $PHP_SELF, ....;
}
if ($REQUEST_METHOD == 'POST')
{
if ( validate_fields(...) )
{
// do something with the data...
}
else
{ // one or more fields not correct, redisplay the form
generate_form(...);
}
else
{ // must be a GET, display an empty form:
generate_form(...);
}
if ($REQUEST_METHOD == 'POST')