fareedreg Posted December 21, 2009 Share Posted December 21, 2009 I am posting my three php form .. through which i am submitting my data to sql server... first is submit.php in which i am accepting data from user... second is validate.php in that one i am validating data entered by user and in third one i am making a connection with database and firing insert query.. but I would like to know IS THERE IS ANY WAY THROUGH WHICH I CAN VALIDATE MY DATA IN same file submit.php...coz if there is any validation error occured user has to entered all data again. because submit.php post data for validation to validate.php and if validate.php generate any error all data must be retype... Or any other way available...thanks file codes below.. Please make it for me as example [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/185922-please-help-me-with-form-validation/ Share on other sites More sharing options...
defeated Posted December 21, 2009 Share Posted December 21, 2009 Here is the long way around... First. In submit.php you have an if statement. If it validates you let it send. Easier to show you.. $each_param=$_GET['each_param']; //get all your parameters from the submitted form /* Validation checks. If valid $validation='valid;'. If not valid $error .=','.$each_param; */ If($validation='valid') { /* Send code */ }//end if else { //Recreate the page the form is on target is still submit.php (this page) echo "<input type='whatever' name='each_param_name' value='$each_param' />"; $error_values=explode(',',$error); foreach ($error_values as $key =>$error_content) { if ($error_content == $each_param) { echo "<br />Error field - please correct" ; }//end foreach }//end else Hope that makes sense. From a user standpoint, what happens is that if they enter non-valid data, they get the input screen again with an error message below the input field. What actually happens is that if the user enters non-valid data, they get served what looks like the same page again with error messages below any field that requires correction. They are however not on the same page, but are actually on send.php within the else section of the code. This sort of validation is better done with ajax, where the input can be checked as the user inputs data - slick! But, if you have not got to ajax yet, then this works and keeps the information that users input. Link to comment https://forums.phpfreaks.com/topic/185922-please-help-me-with-form-validation/#findComment-981860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.