Re: [PHP] Question about form submitting
On Apr 3, 2007, at 1:13 PM, Mário Gamito wrote: Hi, Sorry for the lame question, but i didn't find a satisfactory answer in the web. I have this subscribe form (subscribe.php) and on submit i have to check for errors: a) password and password confirmation mismatch; b) missing filled fields c) check e-mail validity d) etc. My question is how do i make all these possibilities show a different error message without leaving subscribe.php ? I know that the for action must be subscribe.php, from there i'm blind as a bat. Any help would be appreciated. Warm Regards -- :wq! Mário Gamito - urlencode($_POST['field2'])."&field3=".urlencode($_POST ['field3']); header ("location: subscribe.php?error=someError$list"); exit; } } else if ($_GET['error']) { // SESSION $field1 = $_SESSION['field1']; $field2 = $_SESSION['field2']; $field3 = $_SESSION['field3']; // GET $field1 = urldecode($_GET['field1']); $field2 = urldecode($_GET['field2']); $field3 = urldecode($_GET['field3']); } ?> ... Field 1: Field 2: Field 3: ... ... // Be sure to destroy the error fields so that they don't show up next submit unset ($_SESSION['error']); ?> - That's one way to specify an error for each field. It's tedious, but forms are. Hope that helps. ~Philip -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about form submitting / clarification
Mário Gamito wrote: Hi, Of the three items you specify a and b should be handled with Javascript 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 think i was misunderstood. 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']) : ' '; Your Name: ' /> 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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about form submitting / clarification
Hi, > Of the three items you specify a and b should be handled with Javascript > 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 think i was misunderstood. 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 -- :wq! Mário Gamito -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about form submitting
Tijnema ! wrote: On 4/3/07, Mário Gamito <[EMAIL PROTECTED]> wrote: Hi, Sorry for the lame question, but i didn't find a satisfactory answer in the web. I have this subscribe form (subscribe.php) and on submit i have to check for errors: a) password and password confirmation mismatch; b) missing filled fields c) check e-mail validity d) etc. My question is how do i make all these possibilities show a different error message without leaving subscribe.php ? I know that the for action must be subscribe.php, from there i'm blind as a bat. Any help would be appreciated. Warm Regards -- :wq! Mário Gamito This can only be done with Javascript if you don't want to leave the page. And so, you're on the wrong list, search for a javascript list :) Tijnema Actually, that's not quite true. It's usually easier in Javascript, but if you want to do a pure PHP method, read on. This does require that you use the POST method for your form, but that's usually preferred anyway. // Regular form contents go here This uses the PHP SCRIPT_NAME server variable for the form name so that you don't have to worry about the script location and you can move it if necessary without having to change the script. I copied this from PHP Cookbook by O'Reilly. It's not a bad book, if you can get it where you are... Lori -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about form submitting
Mário Gamito wrote: Hi, Sorry for the lame question, but i didn't find a satisfactory answer in the web. I have this subscribe form (subscribe.php) and on submit i have to check for errors: a) password and password confirmation mismatch; b) missing filled fields c) check e-mail validity d) etc. My question is how do i make all these possibilities show a different error message without leaving subscribe.php ? I know that the for action must be subscribe.php, from there i'm blind as a bat. Any help would be appreciated. Warm Regards -- _ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about form submitting
On 4/3/07, Dave Goodchild <[EMAIL PROTECTED]> wrote: Not true. You can submit the form back to itself as many times as required by making the form action $_SERVER['PHP_SELF'] and checking for various sequences and outputting different html in each case. You're then leaving the page and reloading it Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Question about form submitting
Not true. You can submit the form back to itself as many times as required by making the form action $_SERVER['PHP_SELF'] and checking for various sequences and outputting different html in each case.
Re: [PHP] Question about form submitting
On 4/3/07, Mário Gamito <[EMAIL PROTECTED]> wrote: Hi, Sorry for the lame question, but i didn't find a satisfactory answer in the web. I have this subscribe form (subscribe.php) and on submit i have to check for errors: a) password and password confirmation mismatch; b) missing filled fields c) check e-mail validity d) etc. My question is how do i make all these possibilities show a different error message without leaving subscribe.php ? I know that the for action must be subscribe.php, from there i'm blind as a bat. Any help would be appreciated. Warm Regards -- :wq! Mário Gamito This can only be done with Javascript if you don't want to leave the page. And so, you're on the wrong list, search for a javascript list :) Tijnema -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Question about form submitting
Hi, Sorry for the lame question, but i didn't find a satisfactory answer in the web. I have this subscribe form (subscribe.php) and on submit i have to check for errors: a) password and password confirmation mismatch; b) missing filled fields c) check e-mail validity d) etc. My question is how do i make all these possibilities show a different error message without leaving subscribe.php ? I know that the for action must be subscribe.php, from there i'm blind as a bat. Any help would be appreciated. Warm Regards -- :wq! Mário Gamito -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php