The way I do this is I have two files. One for the form, called 'login.php' and one to submit it to called 'loginsubmit.php
In login.php, all the fields would take their default values from their $_POST entry. Here's an example:
<?php
echo <<<HereDocString
<input type=text name=loginUsername value="$_POST[loginUsername]">
HereDocString;
?>
Of course, if there is no $_POST entry for 'loginUsername' then the value field will come out blank.
Also, there's some sort of error field up the top, like this:
<div class=ErrorDisplay>
<?php
echo $errorMessage;
?>
</div>
In loginsubmit.php, first thing to do is check for errors. If there are any errors, this code will execute:
<?php
$errorMessage = 'Some error message';
include 'login.php';
exit();
?>
and that's it. Notice that login.php is already programmed to print the error if there is one, and also to reprint the fields that have already been filled in.
Hope this helps.