Well from my personal experience the best way I found to do this was to do the validation code before all of the form display code, and to use variables to print in the default values if they exist... for example:
<?php
if(isset($submitpage1))
{
if(strlen($test)>0)
$pagenumber=2;
else
$pagenumber=1;
}
if($pagenumber=1)
{
?>
<form method=post action="/test.php4">
<input type="text" name="test" value="<?php echo $test ?>">
<input type="submit" name="submitpage1">
</form>
<?php
}
?>
This is pretty crude example code but I think you can get the idea. Personaly I like to ad an error log variable to my scripts so that I can validate every item on the page and then report all the bad ones at one time.
example:
if (strlen($test)<0)
$errorlog[] = "Test is not long enough"
if (strlen($test2)<0)
$errorlog[] = "Test2 is not long enough"
and so on...
It's quite simple to do the error check after all the actual validation code like so.
if(count($errorlog)>0)
{
echo 'The following errors were found in your submission';
for($i=0;$i<count($errorlog);$i++)
{
echo $errorlog[$i].'<br>';
}
$pagenumber=1;
}
else
$pagenumber=2;
After which you just use the $pagenumber variable to choose which form to show. And use the value=<?php echo $value ?> methood to re-display the data on the form.
This is kinda crudely done but it's quite easy to script and very easy to maintain, if you want a more in-depth description of this methood then feel free to contact me. 🙂