SilentQ-noob- Posted July 20, 2007 Share Posted July 20, 2007 this is my code in _form.php <? if (isset($_POST['name'])) { $name_temp = $_POST['name']; } else { $name_temp = ""; } if (isset($_POST['lastname'])) { $lastname_temp = $_POST['lastname']; } else { $lastname_temp = ""; } if (isset($_POST['email'])) { $email_temp = $_POST['email']; } else { $email_temp = ""; } ?> <caption color="red">All Fields Are Required</caption> <table border="1"> <form action="form_complex_process.php" method="post"> <tr><td>Name:<input type="text" name="<? echo $name_temp; ?>" /><br /></td></tr> <tr><td>Last Name: <input type="text" name="<? echo $lastname_temp; ?>" /></td></tr> <tr><td>E-mail:<input type="text" name="<? echo $email_temp; ?>" /></td></tr> </table> <select name="dropdownbox"> <option value="chooseone" selected >--Choose one--</option> <option value="webmaster" <? if ($selecter=="webmaster") { echo " selected"; } ?>>Web Master</option> <option value="programmer" <? if ($selecter=="programmer") { echo " selected"; } ?>>Programmer</option> <option value="manager" name="selecter"<? if ($selecter=="manager") { echo " selected"; } ?>>Manager</option> <option value="serveradministrator" <? if ($selecter=="serveradministrator") { echo " selected"; } ?>>Server Administrator</option> </select> <br /> <input type="radio" name="button1" value"subscribe" checked />I wish to subscribe <input type="radio" name="button1" value"dontsubscribe" />No, I do not wish to subscribe <input type="submit" value="Submit" /> </form> </body> this is my code in form_process.php <body> <style type="text/css"> <!-- .style4 {color:red} --> </style> <? $name = $_POST['name']; $lastname = $_POST['lastname']; $email = $_POST['email']; $selecter = $_POST['dropdownbox']; $errors = ""; if (empty($name)){ $errors .="<span class='style4'>"."*The name field has not been filled out <br>"."</span>"; } if (empty($lastname)) { $errors .="<span class='style4'>"."*The last name field has not been filled out <br>"."</span>"; } if (empty($email)) { $errors .="<span class='style4'>"."*The email field has not been filled out <br>"."</span>"; } if( !strstr ($email, "@" ) ) { $errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>"; } if( !strstr ($email, "." ) ) { $errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>"; } if ($selecter == "chooseone" ) { $errors .= "<span class='style4'>"."*You need to choose a Profession<br>"."</span>"; } if (empty($errors)){ echo "Thanks for filling out our form"; } else { echo $errors; include ("_form.php"); } ?> I'm trying to make the form re-appear with the values the user put in, but with the error message stating which one wasnt entered. For example, all but "name" is filled out, so form re-appears with previously entered data, but empty name field and "Name not entered" message. I thought this should work but all it does is print all the $error messages regardless of whether user entered data or not. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted July 20, 2007 Share Posted July 20, 2007 i just built them as one for testing it seams ok <body> <style type="text/css"> <!-- .style4 {color:red} --> </style> <?php if( isset($_POST['dropdownbox']) ) { $name = $_POST['name']; $lastname = $_POST['lastname']; $email = $_POST['email']; $selecter = $_POST['dropdownbox']; $errors = ""; if (empty($name)){ $errors .="<span class='style4'>"."*The name field has not been filled out <br>"."</span>"; } if (empty($lastname)) { $errors .="<span class='style4'>"."*The last name field has not been filled out <br>"."</span>"; } if (empty($email)) { $errors .="<span class='style4'>"."*The email field has not been filled out <br>"."</span>"; } if( !strstr ($email, "@" ) ) { $errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>"; } if( !strstr ($email, "." ) ) { $errors .= "<span class='style4'>"."*Invalid e-mail<br>"."</span>"; } if ($selecter == "chooseone" ) { $errors .= "<span class='style4'>"."*You need to choose a Profession<br>"."</span>"; } if (empty($errors)){ echo "Thanks for filling out our form"; }else { echo $errors; //include ("_form.php"); } } if (isset($_POST['name'])) { $name_temp = $_POST['name']; } else { $name_temp = ""; } if (isset($_POST['lastname'])) { $lastname_temp = $_POST['lastname']; } else { $lastname_temp = ""; } if (isset($_POST['email'])) { $email_temp = $_POST['email']; } else { $email_temp = ""; } ?> <caption color="red">All Fields Are Required</caption> <table border="1"> <form method="post"> <tr><td>Name:<input type="text" name="<? echo $name_temp; ?>" /><br /></td></tr> <tr><td>Last Name: <input type="text" name="<? echo $lastname_temp; ?>" /></td></tr> <tr><td>E-mail:<input type="text" name="<? echo $email_temp; ?>" /></td></tr> </table> <select name="dropdownbox"> <option value="chooseone" selected >--Choose one--</option> <option value="webmaster" <? if ($selecter=="webmaster") { echo " selected"; } ?>>Web Master</option> <option value="programmer" <? if ($selecter=="programmer") { echo " selected"; } ?>>Programmer</option> <option value="manager" name="selecter"<? if ($selecter=="manager") { echo " selected"; } ?>>Manager</option> <option value="serveradministrator" <? if ($selecter=="serveradministrator") { echo " selected"; } ?>>Server Administrator</option> </select> <br /> <input type="radio" name="button1" value"subscribe" checked />I wish to subscribe <input type="radio" name="button1" value"dontsubscribe" />No, I do not wish to subscribe <input type="submit" value="Submit" /> </form> </body> Quote Link to comment Share on other sites More sharing options...
SilentQ-noob- Posted July 20, 2007 Author Share Posted July 20, 2007 Thanks for reply, figured it out in the mean time, in the form it had to be value="<? echo $name; ?>" , not name="... 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.