heartily regards from me
I need to retain values in text boxes after submit button on click if found error.
basically the thing I want, if user left any fields blank and press save button then error message pop up and without refreshing the page it takes back the user to the form where he just have to fill the fields that were left blank… below is my code
<html>
<form method="post" action="">
Enter Name : <input type="text" name="name" /><br/>
Enter Password : <input type="password" name="pass" /><br/>
<input type="submit" name="save" value="Save" />
</form>
</html>
php code
<?php
if (isset($_POST["save"]))
{
$name = $_POST["name"];
$pass = $_POST["pass"];
if (($name == '') && ($pass == ''))
{
echo "Fields Must Be Filled...";
exit();
}
if ($name == '') {
echo "Enter Name...";
exit();
}
if ($pass == '') {
echo "Enter Password...";
exit();
}
else
{
echo "Your name " . $name;
echo "<br/>";
echo "Your Password " . $pass;
}
}
?>
First, a little easier approach for your POST handling. You can do a
Now, all your POSTs will be in variables with the name of the field.
After processing them for errors and more, and you wish them to be in your form element’s value. You can just use the variable
Or, if you use the POST
Best regards.
Jonas
Working code 🙂