I have a simple form with validation that gets submitted to itself. That all works fine and dandy, but what my problem is is when the form gets submitted to itself I lose my variables if the form doesn't validate. I've tried many different ways to put my vars into the form and have then show up when the form doesn't validate, but I just can't seem to get it to work.
Here is my code:
Code: Select all
<?php
//the form
$form='
<form method="post">
<input type="hidden" name="s" value="y"/>
Name: <input type="text" name="name" value="IWANTMYVALUEHERE"/><br/>
Age: <input type="text" name="age" value="IWANTMYVALUEHERE"/><br/>
<input type="submit"/>
</form>
';
//check the form
//if form has been submitted
if ($_POST['s']=='y')
{
//if name and age
if (($_POST['name']!=null) && ($_POST['age']!=null))
{
//output name and age
echo $_POST['name'] . ' is ' . $_POST['age'] . "\n";
}
//if not name and age
else
{
//output form
echo $form;
}
}
//if form has not been submitted
else
{
//output form
echo $form;
}
?>Can anyone give me some advice or help with this? It would be much appreciated.
LZ