[PHP] Validating forms and showing errors
Hi everybody, This might be a RTFM or STFW-question, but I haven't found it. I want to validate a form (in page1.php) to check if the user has entered a correct email-adress and more, and if he needs to correct some fields, I'd like to display the form again with all correct values filled in and the incorrect fields hightlighted. To make it a bit more difficult I've decided to POST to another file (post.php) which validates the information and redirects the user (with Header - Location) to page1.php if he has to correct the errors. If the form is correctly filled in then he will be redirected to page2.php. This is to prevent the browser for asking him if he wants to repost data if he hits 'Refresh'. Now I want to know how to pass information from post.php to page1.php since the form page (page1) needs to know what was incorrect and what was correct so that it can hightlight the bad fields. I don't want to stick it in the URL since it would be too ugly, but I do have session variables I can stick them in. Is this the way to go? Or is there a better solution? I guess many of you have fought with this before so I know you can help me ;) Thanks in advance, Victor -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Validating forms and showing errors
These are the five methods I know of getting the data back to the original form. 1. Client side cookies 2. Server side cookies/session variables 3. URL 4. hidden form 5. submit back on yourself Take your pick Martin -Original Message- From: Victor Boivie [mailto:[EMAIL PROTECTED]] Sent: Monday, May 27, 2002 3:19 PM To: [EMAIL PROTECTED] Subject: [PHP] Validating forms and showing errors Hi everybody, This might be a RTFM or STFW-question, but I haven't found it. I want to validate a form (in page1.php) to check if the user has entered a correct email-adress and more, and if he needs to correct some fields, I'd like to display the form again with all correct values filled in and the incorrect fields hightlighted. To make it a bit more difficult I've decided to POST to another file (post.php) which validates the information and redirects the user (with Header - Location) to page1.php if he has to correct the errors. If the form is correctly filled in then he will be redirected to page2.php. This is to prevent the browser for asking him if he wants to repost data if he hits 'Refresh'. Now I want to know how to pass information from post.php to page1.php since the form page (page1) needs to know what was incorrect and what was correct so that it can hightlight the bad fields. I don't want to stick it in the URL since it would be too ugly, but I do have session variables I can stick them in. Is this the way to go? Or is there a better solution? I guess many of you have fought with this before so I know you can help me ;) Thanks in advance, Victor -- 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
RE: [PHP] Validating forms and showing errors
I want to validate a form (in page1.php) to check if the user has entered a correct email-adress and more, and if he needs to correct some fields, I'd like to display the form again with all correct values filled in and the incorrect fields hightlighted. I tend to do this sort of thing using includes and a single page. If it's the first time being loaded (no post data) then just display the form. If it's been submitted then process the data and decide what to do from there. If there are errors, redisplay the form showing errors that need to be corrected. If there's no errors, move along to the next stage in the process. To make it a bit more difficult I've decided to POST to another file (post.php) which validates the information and redirects the user (with Header - Location) to page1.php if he has to correct the errors. If the form is correctly filled in then he will be redirected to page2.php. This is to prevent the browser for asking him if he wants to repost data if he hits 'Refresh'. That's a browser decision based on the existence of post data - in other words, just because the form posts to a different file doesn't mean that if you hit reload it won't re-post the data. hightlight the bad fields. I don't want to stick it in the URL since it would be too ugly, but I do have session variables I can stick them in. Is this the way to go? Or is there a better solution? There are ways to do it - cookies or hidden forms spring to mind - but first it's worth working out if the effort is worth it. It won't prevent a page refresh from re-posting data (although you could test for that in your php and deal with it accordingly). CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php