That's easy, too:
if ($REQUEST_METHOD == 'POST')
{
// process the variables posted by the form
}
else
{
// generate the form, including the statement to POST back to ourselves
}
Actually, quite often I find myself wanting to do data validation on the form,
and not wanting to depend on the users having Javascript enabled, I do it
in PHP. As a very scaled-down example:
<?php
function build_form()
{
global $PHP_SELF, $name, $pwd;
echo "<form action=\"$PHP_SELF\" method=\"POST\">\n";
echo "Name: <input type=\"text\" name=\"_name\" value=\"$_name\"><br>\n";
echo "Password: <input type=\"password\" name=\"_pwd\"><br>\n";
echo "<input type="submit" value=\"Log In\">\n";
echo "</form>\n";
}
if ($REQUEST_METHOD != 'POST')
{
build_form();
}
elseif ($name == '' )
{
echo "Please enter your Login Name<br>";
build_form();
}
elseif ($pwd == '' )
{
echo "Please enter your password<br>";
build_form();
}
else
{
// do something with $name and $pwd
}
?>