Sticky forms with PHP
<p>I have a form whose action is set to itself. I want it this way so that is returns previously entered values if you have already submitted the form once (with an error), so that you don't have to completely redo the form. I have:</p>

<pre><code>&lt;?php

if (isset($_POST['submit'])) {
$firstname= $_POST['firstname'];
$lastname= $_POST['lastname'];
$output_form= false;

if ($firstname== "empty($firstname) &amp;&amp; empty($lastname)) {
echo "you forgot you first and last names!!";
$output_form= true;
}

if (!empty($firstname) &amp;&amp; empty($lastname)) {
echo "you forgot your last name.";
$output_form= true;
}

if (empty($firstname) &amp;&amp; !empty($lastname)) {
echo "you forgot your firstname.";
$output_form= true;
}

if (!empty($firstname) &amp;&amp; !empty($lastname)) {
echo "good job!!";
}

}

else 
{
$output_form= true;
}

if ($output_form) { 
?&gt;

&lt;form method="post" action=" &lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
First Name: &lt;input type="text" name="firstname" value="&lt;?php echo $firstname ?&gt;"/&gt;
Last Name: &lt;input type="text" name="lastname" value="&lt;?php echo $lastname ?&gt;"/&gt;
&lt;input type="submit" name="submit" value="submit"/&gt;
&lt;/form&gt;

&lt;?php 
}
?&gt;
</code></pre>

<p>If the form has not yet been submitted the <code>$output_form</code> variable will return true in my if statement. But I get an error because the variables <code>$firstname</code> and <code>$lastname</code> are not yet defined (because the <code>isset($_POST['submit']</code> returns a <code>false</code> value; the form has not yet been submitted) What can I do to keep my form "sticky"?</p>
