-
Validating Form
I wish to check validation of the form by PHP (without Java script).
But if the form doesn't validate, I can redirect the page by
PHP Code:
header("Location: Myform.php");
this code.
But all form fields will be reset on that time.
So that page will not be a user friendly.
If I can post data automatically to Myform.php I can do this simply!:rolleyes:
Most of the sites have the technology what I like. But I don't know how to do that!:(
Can you help me to fulfill my desire please?
-
Re: Validating Form
Just fill out the form fields using PHP.
PHP Code:
<input name="field1" value="<?php echo $field1 ?>">
Make sure that you have validated $field1 first and used the htmlentities or htmlspecialchars functions.
-
Re: Validating Form
This is my sample form
FormPage:
PHP Code:
<html>
<head>
<title>Validating Form</title>
</head>
<body>
<form action="ValidatingPage.php" method="POST">
<P><strong>Your age:</strong><br><input name="yage" type="text" value="<?php echo($yage);?>"></P>
<input name="" type="submit">
</form>
</body>
Validating Page:
PHP Code:
<?php
if (!$_POST[yage]|| $_POST[yage]<13)
{
$yage=htmlspecialchars($_POST[yage]);
header("Location: FormPage.php");
exit;
}
else echo("Form Checked");
?>
Am I correct?
But Sorry, it is not working.
I think I must have made a mistake. But I don't know it!
Can you able to guess it?
-
Re: Validating Form
If you redirect using header("Location"), then whatever data was sent through the POST request will be lost. You could make the page that has the form make the request to itself, then handle the data and if successful, then redirect to another page, if not successful, then show the data that you can get through $_POST in the appropriate fields of your form (you are in the same page again).
That's one method...