I have form.php containing 2 textfields to input a name and a date, and a submit button (< form action="check.php method="post">....)
I'd like to know how I can display back the form after the check.php found the error of the input which also display the previuos corrected input
ex : user inputed correct the name but incorrected the date, the check.php will forward back to the form and prompt user that he/she inputed the date incorrected...also it still display the corrected name in the field name.
thnaks
new to PHP...help
Moderator: General Moderators
I typed some php end tags which aren't appearing in this post - hope you can figure out where : (
You can have a single script which either processes or displays a form something like this:
This would catch empty form fields. If you want to validate the data add some more ORs, eg:
That's just an example which checks for alphanumeric characters in name - add any kind of check you need.
If you include the form, you can set initial values for the form fields like this:
<input type="text" name="name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
(I'm assuming your form is in html)
If the user input fails a check, any values entered when the form was submitted will be redisplayed; if this is the first visit to the form page, nothing is displayed - POST vars aren't set.
To create an error message, add some code to the form such as:
Again, substitute whatever check you want to make instead of ctype_alpha().
You might want to add a block of code as above for each of the validation checks you have, so that a specific error message is displayed for each failed test. Eg if you check if a name is registered you'd maybe want a 'This name is not registered' message when it fails.
You can have a single script which either processes or displays a form something like this:
Code: Select all
IF (!isset($_POST['name']) OR !isset($_POST['date'])) {
// include the form
} ELSE {
// process the POST data
}Code: Select all
IF (!isset($_POST['name']) OR !isset($_POST['date']) OR !ctype_alpha($_POST['name'])) ..etcIf you include the form, you can set initial values for the form fields like this:
<input type="text" name="name" value="<?php echo htmlspecialchars($_POST['name']); ?>">
(I'm assuming your form is in html)
If the user input fails a check, any values entered when the form was submitted will be redisplayed; if this is the first visit to the form page, nothing is displayed - POST vars aren't set.
To create an error message, add some code to the form such as:
Code: Select all
<?php
IF (!ctype_alpha($_POST['name'])) {
echo 'Please enter name again';
}
?>You might want to add a block of code as above for each of the validation checks you have, so that a specific error message is displayed for each failed test. Eg if you check if a name is registered you'd maybe want a 'This name is not registered' message when it fails.
Last edited by McGruff on Thu Aug 11, 2005 12:26 pm, edited 1 time in total.