NickG21 Posted December 21, 2006 Share Posted December 21, 2006 i was wondering how exactly i could repost the data that was entered in my form if everything passes through the validation in the script below. thank you[code]<html><head></head><body><form action="testing1.php" method="post"><input type="text" name="text1" value="Your Name"><br/><input type="text" name="text2" value="Zip" maxlength="5"><br/><input type="text" name="email" value-"E-Mail"><br/><input type="submit" name="submit" value="submit"><br/><input type="hidden" name="submitted" value="1"></form><?phpif ($_POST['submitted'] == 1) {$email = $_POST['email'];$name = $_POST['text1'];$number = $_POST['text2'];// check e-mail address// display success or failure messageif (!preg_match("/^([a-zA-Z])+/",$_POST['text1'])){echo("Text Only As Your Name, Please Re-Submit");}if (!preg_match("/^([0-9])+/",$_POST['text2'])){echo("Invalid Number Scheme");}if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email'])){die("Invalid e-mail address");}echo "Valid e-mail address, processing...";}$submitted=0;?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31505-re-posting-data-in-a-form/ Share on other sites More sharing options...
ted_chou12 Posted December 21, 2006 Share Posted December 21, 2006 can you explain it a bit more, nick? what do mean by repost? do you want to recall the data or something? Quote Link to comment https://forums.phpfreaks.com/topic/31505-re-posting-data-in-a-form/#findComment-145933 Share on other sites More sharing options...
NickG21 Posted December 21, 2006 Author Share Posted December 21, 2006 i want to take the validated data and if a different piece didn't pass validation be able to pass the good data back into the form so that the entire form doesn't need to be refilled if there is only one error. i am starting on a small scale with only these three text boxes but there will be many more before i am complete. thank you Quote Link to comment https://forums.phpfreaks.com/topic/31505-re-posting-data-in-a-form/#findComment-145938 Share on other sites More sharing options...
ted_chou12 Posted December 21, 2006 Share Posted December 21, 2006 why dont you do this:[code]<html><head></head><body><form action="testing1.php" method="post">Your Name<input type="text" name="text1" value="<?echo"$name"?>"><br/>Zip code<input type="text" name="text2" maxlength="5" value="<?echo"$number"?>"><br/>E-mail<input type="text" name="email" value="<?echo"$email"?>"><br/><input type="submit" name="submit" value="submit"><br/><input type="hidden" name="submitted" value="1"></form><?phpif ($_POST['submitted'] == 1) {$email = $_POST['email'];$name = $_POST['text1'];$number = $_POST['text2'];// check e-mail address// display success or failure messageif (!preg_match("/^([a-zA-Z])+/",$_POST['text1'])){$name = "";echo("Text Only As Your Name, Please Re-Submit");}if (!preg_match("/^([0-9])+/",$_POST['text2'])){$number = ""echo("Invalid Number Scheme");}if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/", $_POST['email'])){$email = ""die("Invalid e-mail address");}echo "Valid e-mail address, processing...";}$submitted=0;?></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31505-re-posting-data-in-a-form/#findComment-145946 Share on other sites More sharing options...
NickG21 Posted December 21, 2006 Author Share Posted December 21, 2006 doesn't that code just store a null value in my variable if it doesn't pass the validation? how do i make the form re-display the values that are stored and did pass? sorry, im very new at this Quote Link to comment https://forums.phpfreaks.com/topic/31505-re-posting-data-in-a-form/#findComment-145957 Share on other sites More sharing options...
HuggieBear Posted December 21, 2006 Share Posted December 21, 2006 No, the provided code does what you want it too.It doesn't put anything in as the value on the first display of the form, but once you've filled the fields in and submitted, the default values will be set to what you put in the fields.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/31505-re-posting-data-in-a-form/#findComment-145960 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.