Re: [PHP] Question about form submitting / clarification
- From: llay@xxxxxxxxxxxxxxxxxxx (Lori Lay)
- Date: Tue, 03 Apr 2007 15:43:06 -0400
Mário Gamito wrote:
Hi,
Of the three items you specify a and b should be handled with JavascriptI think i was misunderstood.
in an onsubmit handler. The error messages would be generated by this
handler. Email validity would have to be handled by the web server and
your php script, usually by trying the address.
I know how to do the error handling.
What i don't know is how to display the error messages in the same page
as the submit form.
Warm Regards
To expand on my previous response: create a function that displays the form and takes an "errors" array as an argument. The function would display the form with print commands that would display the error messages. If there are no errors, then just the form is displayed, but if there are errors they are printed right next to the form element.
For example:
in display form function:
$defaults['name'] = isset($_POST['name']) ? htmlentities($_POST['name']) : ' ';
<td>Your Name:</td>
<td><?php print_error('name', $errors) ?>
<input type='text' name='name' value='<?php echo $defaults['name'] ?>' /></td>
You will also need a print error function that takes the input element name and errors array as arguments. The $defaults variable is set to blank if the form is being displayed for the first time or the value input by the user if the form is being redisplayed after validation by using the POST variables.
Lastly you will need a form validation function that would populate the errors array. This would be an associative array with the form field names as keys and the error messages as values.
The entire code is available in the book I mentioned previously. I can't replicate it here due to the obvious copyright issues, although the example code is available on O'Reilly's site (http://www.oreilly.com/) Search for PHP Cookbook and select the second edition.
This is all very difficult to explain in an email, but hopefully I've given you enough to chew on, as it were...
Lori
.
- References:
- Question about form submitting
- From: Mário Gamito
- Re: [PHP] Question about form submitting / clarification
- From: Mário Gamito
- Question about form submitting
- Prev by Date: Re: [PHP] Why do some pages repeat a previous page's action(s) after redirect?
- Next by Date: Re: [PHP] Downloads for subsrcibers only
- Previous by thread: Re: [PHP] Question about form submitting / clarification
- Next by thread: Re: [PHP] Question about form submitting
- Index(es):
Relevant Pages
|