hakimserwa Posted July 21, 2012 Share Posted July 21, 2012 hello to all of you again. i am working on a registration form of about 15 fillable fields, i have set some validation rules to this form but what i want is if one of the rule is not met along the way, lets say the seventh field but all the 1 to 6 and 8 to 15 are were correct, the form on submision must not cancel the initial correct values. it must echo a message at the top but his field values will still exist just what will be needed is him to correct the wrong field and submit again. Quote Link to comment Share on other sites More sharing options...
Fadion Posted July 21, 2012 Share Posted July 21, 2012 You'll need to set the inputs values to the post/get data, so they get filled automatically on submit. Supposing you're sending the form via post: <input type="text" name="full_name" value="<?php echo $_POST['full_name']; ?>"> <input type="text" name="email" value="<?php echo $_POST['email']; ?>"> Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 21, 2012 Author Share Posted July 21, 2012 it seems no one is willing to help on this but this was my novice way of solving it and i thought some other mates may find it usefull atleast for the start. if you know how to echo error messages from your process.php or even if you have done self form submission, then you can also use php to archieve form data rataition on submit if the validation was failed. you make your form, it posts data to your process file in this case its self submission, then you validate to see if some criterias are met before inserting that data to your table. then you echo an error messege back to the form in validation was failed. the same way you echo errors is the same way i echoed the form data back to the form using a temporary valuable $field1 and 2 and 3 and so on. then i globalised the field valuables and places them in the form as values. so every time i have an error trigered on my form page, the temporary field valuable is also trigered and desplayed in the value of the input field on my html form. example <?php $first_name = $_POST['First_Name']; $last_name = $_POST['Last_Name']; $age = $_POST['Age']; $contact_number = $_POST['Contact_Number']; $email_address = $_POST['Email_Address']; $country = $_POST['Country']; if(isset($_POST['send_info'])){ if(!trim($first_name)){ $messege=" Please Provide Your First Name!"; }elseif (is_numeric($first_name)){ $messege = "Names Must be alphabets only!"; }elseif(preg_match("([0-9])", $first_name) ){ $messege = "No Numbers Are allowed in Name Fielsds"; }elseif(!trim($last_name)){ $messege="Sorry Please Provide Your Last Name!"; $field1= $first_name; }elseif (is_numeric($last_name)){ $messege = "Names Must be alphabets only!"; $field1= $first_name; }elseif(preg_match("([0-9])", $last_name) ){ $messege = "No Numbers Are allowed in Name Fielsds"; $field1= $first_name; }elseif(!trim($contact_number)){ $messege="Sorry Please Provide Your Contact Number!"; $field1= $first_name; $field2= $last_name; $field3= $age; }elseif(preg_match("([a-z][A-Z])", $contact_number) ){ $messege = "No Alphabates Are Allowed in Contact Fielsds"; $field1= $first_name; $field2= $last_name; $field3= $age; }elseif(empty($email_address)){ $messege="Sorry Please Provide Your Email Address!"; $field1= $first_name; $field2= $last_name; $field3= $age; $field4= $contact_number; }elseif(empty($country)){ $messege="Sorry Please Provide Your Country!"; $field1= $first_name; $field2= $last_name; $field3= $age; $field4= $contact_number; $field5= $email_address; }elseif(empty($problem)){ $messege="Sorry Please Explain Your Problem!"; $field1= $first_name; $field2= $last_name; $field3= $age; $field4= $contact_number; $field5= $email_address; $field6= $country; }elseif($messege==false){ $date = date("d/m/y"); $sql = mysql_query("INSERT INTO clients (`id`, `Client Id`, `First Name`, `Last Name`, `Age`, `Contact Number`, `Email Address`, `Problem`, `Country`,`Consultation Fees`, `Date Joined`, `Status`) VALUES ('','','$first_name','$last_name','$age','$contact_number','$email_address','$problem','$country','$consultation_fees', '$date', 'New')")or die('Error: ' . mysql_error()); $messege=" form subbmited sucessfully 1 record added!"; }else{ echo $messege; } } ?> Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 21, 2012 Author Share Posted July 21, 2012 You'll need to set the inputs values to the post/get data, so they get filled automatically on submit. Supposing you're sending the form via post: <input type="text" name="full_name" value="<?php echo $_POST['full_name']; ?>"> <input type="text" name="email" value="<?php echo $_POST['email']; ?>"> SORRY I WROTE THIS BEFORE YOU REPLIED Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted July 21, 2012 Share Posted July 21, 2012 You would use an array to hold the error messages, with the array index name relating it to the form field (if you want to output the error message next to the corresponding form field), so that you can validate and output messages for all the fields at one time, rather than outputting the first validation error, resubmitting the form, outputting the next validation error.... Quote Link to comment Share on other sites More sharing options...
hakimserwa Posted July 21, 2012 Author Share Posted July 21, 2012 it seems like a great idea to learn can you please show me an example. but in the previous post what i was trying to archieve was form fields to retain the filled in data when submted but failed to pass validation. I would appreciate any better idea than myn as i am still a novis i like learning Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.