richrock Posted September 25, 2008 Share Posted September 25, 2008 Well, it's that time again. Yes. I am stuck. Had a mate of mine show me how to error check a form once submitted. The code he showed me has: // Add User Details function checkFormValidation() { // Generate the result errors if anything missed. if (!$firstname) {$errmsg=$errmsg. "- First Name is a required field.<br />"; $continue=false;} if (!$lastnamename) {$errmsg=$errmsg. "- Last Name is a required field.<br />"; $continue=false;} if (!$telephone) {$errmsg=$errmsg. "- Telephone Number is a required field.<br />"; $continue=false;} if (!$username) {$errmsg=$errmsg. "- Username is a required field.<br />"; $continue=false;} if (!$email) {$errmsg=$errmsg. "- Email Address is a required field.<br />"; $continue=false;} //Check for dull people entering data... if (!$continue) { //Error in the input of the form, person entering data is a n00b echo "<strong>Error in form, incorrect data</strong><br />"; echo $errmsg."<br />"; die(); } } Now I'm posting the form to another page (it writes the user details to the DB, loads the page, then displays the details along with a further form... But if something is missing, I'm now on the second page (using <form action="second_page.php"...) and can't get back to the original form without losing the entered form information. Now my thinking is that this will have to be processed by a javascript function to check the form, and if ok, carry on with the $_POST onto the next page. Is this right? Something along the lines of function checkForm ( make sure the form.is.complete; ) I should be able to cope with that. But is there a way to keep it within PHP and push my knowledge further? Rich Link to comment https://forums.phpfreaks.com/topic/125814-error-check-form-going-to-another-page/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2008 Share Posted September 25, 2008 The easiest solution is to have a single page with the form and the form processing code. Then the data that was entered is already available and you can simply echo it in the form field value="..." parameters. Link to comment https://forums.phpfreaks.com/topic/125814-error-check-form-going-to-another-page/#findComment-650552 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.