A simple example of what I mean:
<?php
if (isset($_POST['posted']))
{
$correct = true;
//check if all is right
if (trim($_POST['city'])=="")
{
echo "You haven't filled in City field.<br>";
$correct = false;
}
if (trim($_POST['country'])=="")
{
echo "You haven't filled in Country field.<br>";
$correct = false;
}
if (!$correct)
{
print_form($_POST['city'],$_POST['country']);
}
else
echo "All data OK!";
}
else
print_form("","");
//function definition
function print_form($city, $country)
{
echo <<<END
<FORM ACTION="$_SERVER[PHP_SELF]" METHOD="POST">
<INPUT TYPE="hidden" NAME="posted" VALUE="posted">
City: <INPUT TYPE="TEXT" NAME="city" VALUE="$city"><br>
Country: <INPUT TYPE="TEXT" NAME="country" VALUE="$country"><br>
<INPUT TYPE="SUBMIT" VALUE="Send">
</FORM>
END;
}
?>