I have two arrays:
1)
2)
I then do some validation. If there is trouble, the form outputs again with this :
The problem with this is every time the form is re-outputted the error message pops up, but all the information disappears. The reason this is happening is because as the form is being redisplayed, the $value variable is not being reset with the $_POST data. Is there anyway i can use a foreach statement to both output the form labels, and set the $value variable with the data stored in $_POST?
1)
Code:
$labels = array ("firstname" => "First Name: ", //used for labeling a form
"lastname" => "Last Name: ",
"username" => "User Name: ",
"password" => "Password: ",
"email" => "Email: "
);
Code:
$_POST = array ("firstname" => "john ", //normal output from a form
"lastname" => "doe ",
"username" => "johndoe ",
"password" => "john123 ",
"email" => "john@email.com "
);
Code:
echo "<form action='$_SERVER[PHP_SELF]' method='POST'>";
foreach($labels as $field => $label)
{
echo "<label for='$field'>$label</label>
<input type='text' name='$field' id='$field' value='$value'/>\n";
}
echo "<div id='submit'><input type='submit' value='Submit' />\n";
echo "</form>\n</body>\n</html>";
echo "There were errors with the data you provided:\n";