I'm new to php and i've been reading a few different books. They all seem to have forms that post to themselves, and conditionally handle the form if it has been submited (with a hidden input) and display it if it has not been submited. They also have sticky inputs if some part of the validation failed. All of my forms like this seem to have 2 problems:
1) The values are only sticy for the first re-display
2) Nothing seems to happen on even the second submission (first re-submission) , even if all inputs are now correct, the form will re-fresh with all the fields empty, and nothing will happen after that without refreshing the page.
Here's an example of a typical script that does this:
if (isset($_REQUEST['submited'])) { //process
if (empty($_REQUEST['username']) {
$username = $_REQUEST['username']; //redisplay if validation didn't pass
$error = 'You must enter a username';
} else {
//login
exit;
}
} else { //display
echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">';
if (isset($error)) echo $error;
echo '<input type="text" name="username" id="username" size="20" maxlength="20" value="';
if (isset($username)) echo $username;
echo '" />
echo '<input type="hidden" name="submited" id="submited" value="TRUE" /><input type="submit" name="submit" id="submit" value="Login" />';
echo '</form>';
}
So what can I do so that I could keep re-submitting and keep getting the same username required error, and then when I do correctly enter a username, it correctly processes the script.
I want to give people multiple chances to correct mistakes, and as it is, even if they correct it right the first time, the script fails.
Thanks