seaten Posted March 3, 2006 Share Posted March 3, 2006 Hi I'm pretty new to php,Okay what I'm trying to do is, after the user enters an invalid email address, I want him to re-enter the details for it. I know this sounds pretty simple, but I'm having difficulty with this.This is my code so far://the user enters details<? session_start();session_register('person_name');session_register('person_email');session_register('person_phoneno');?><HTML> <BODY> <FORM method="post" ACTION="CheckWizard1.php"> Contact name:<input type="Text" name="sel_person_name" value=""><br> Contact email:<input type="Text" name="sel_person_email" value=""><br> Contact phoneno:<input type="Text" name="sel_person_phoneno" value=""><br> <input type="Submit" name="submit" value="Details"> </FORM> </BODY></HTML>----------------------------------------------------------------------------------------------------------//Now I will check if the input is valid(in that case go to wizard2.php, if invalid go back to wizard1.php and re-enter details//This is code for CheckWizard1.php<? session_start();?><HTML><? if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $person_email)) { echo "$person_email is not a valid email"; //go back to wizard1, but I cannot put HTML link here <P>Please go to final Submit<a href="wizard1.php"> now </a>.</p> } ?>//else if everything is valid go post details to wizard2.php <FORM method="post" ACTION="wizard2.php"> Contact name:<input type="Text" name="sel_person_name" value=""><br> Contact email:<input type="Text" name="sel_person_email" value=""><br> Contact phoneno:<input type="Text" name="sel_person_phoneno" value=""><br> <input type="Submit" name="submit" value="Details"> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/4010-re-enter-details-for-invalid-email-address/ Share on other sites More sharing options...
php_b34st Posted March 3, 2006 Share Posted March 3, 2006 You could put the form into a variable and then call the variable again, try:[code]//make the forma variable$form = '<FORM method="post" ACTION="CheckWizard1.php"> Contact name:<input type="Text" name="sel_person_name" value=""><br> Contact email:<input type="Text" name="sel_person_email" value=""><br> Contact phoneno:<input type="Text" name="sel_person_phoneno" value=""><br> <input type="Submit" name="submit" value="Details"> </FORM>';[/code]Then replace:[code]<?if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $person_email)) {echo "$person_email is not a valid email";//go back to wizard1, but I cannot put HTML link here<P>Please go to final Submit<a href="wizard1.php"> now </a>.</p>}?>[/code]with:[code]<?if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $person_email)){ echo $person_email.'is not a valid email<br />' .$form; exit();}?>[/code]Also i dont think the rest of the script will work the way you wanted it too, it will just print another form rather than sending the data to the 2nd wizard, you might want to combine the two scripts into one. Quote Link to comment https://forums.phpfreaks.com/topic/4010-re-enter-details-for-invalid-email-address/#findComment-13951 Share on other sites More sharing options...
mainewoods Posted March 3, 2006 Share Posted March 3, 2006 The easiest way to reenter field values entered by the user into the <form> fields when validation of the field(s) fails is to put your <form>, your field validation logic, and your <form> processing logic all in the same page. Untimitely this allows you to do stuff like this:[code]<input type="Text" name="sel_person_email" value="<?php echo $sel_person_email; ?>">[/code]--notice that I embedded php right inside the value="" statement.--To put it all on one page, structure it like this:[code]//test for submittall of your form:if (isset($_POST['submit'])) { //the name of your submit button //retrieve the form field values $sel_person_email = isset($_POST['sel_person_email']) ? $_POST['sel_person_email'] : ''; //... //validation logic goes here if ($fieldsareOK) { //code to store fields in database //either do a redirect at this point or instead zero out the data //fields for reentry of a new record $sel_person_email = ''; //... } //end if} //end if//your form goes here<form >//redisplay fields contents if validation failed<input type="Text" name="sel_person_email" value="<?php echo $sel_person_email; ?>">//... </form> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/4010-re-enter-details-for-invalid-email-address/#findComment-13952 Share on other sites More sharing options...
seaten Posted March 3, 2006 Author Share Posted March 3, 2006 cheers guys i will try this out now Quote Link to comment https://forums.phpfreaks.com/topic/4010-re-enter-details-for-invalid-email-address/#findComment-13963 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.