webdevdea Posted June 18, 2013 Share Posted June 18, 2013 (edited) when the user hits submit and all the fields are filled out it should print out a little welcome note, it is doing everything except that.. help please.. im sure its one of my true or false or something like that but I am lost right now. help please.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <style> body { background-color:#FF00FF; } h1 { color:orange; text-align:center; } p { font-family:"Times New Roman"; font-size:20px; } h1 {text-align:center; } </style> <title>Assignment3</title> </head> <body> <h1>Personal Information </h1> <?php $fName = filter_input(INPUT_POST, "fName"); $lName = filter_input(INPUT_POST, "lName"); $city = filter_input(INPUT_POST, "city"); $state = filter_input(INPUT_POST, "state"); $zipCode = filter_input(INPUT_POST, "zipCode"); $other = filter_input(INPUT_POST, "other"); $chkErrors = FALSE; if(!empty($_POST['fName'])) { $chkErrors = TRUE; } else { echo '****FIRST NAME FIELD REQUIRED*****'; echo "<br> <a href='Assignment3.html'>Go back to form</a>"; } if(!empty($_POST['lName'])) { $chkErrors = TRUE; } else { echo '****LAST NAME FIELD REQUIRED*****'; echo "<br> <a href='Assignment3.html'>Go back to form</a>"; } if(!empty($_POST['city']) && isset($_POST['city'])) { $chkErrors = TRUE; } else { echo '****CITY FIELD REQUIRED*****'; echo "<br> <a href='Assignment3.html'>Go back to form</a>"; } if(!empty($_POST['state'])) { $chkErrors = TRUE; } else { echo '***STATE NAME FIELD REQUIRED*****'; echo "<br> <a href='Assignment3.html'>Go back to form</a>"; } if(!empty($_POST['zipCode'])) { $chkErrors = TRUE; } else { echo '****ZIPCODE FIELD REQUIRED*****'; echo "<br> <a href='Assignment3.html'>Go back to form</a>"; } if(!empty($_POST['other'])) { $chkErrors = TRUE; } else { echo '****TEXT FIELD REQUIRED*****'; echo "<br> <a href='Assignment3.html'>Go back to form</a>"; } if ($chkErrors = FALSE) { echo <<<HERE '<h3> Hi there, $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year. <br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br /> <img src="pup.jpg" width="200" height="175" alt="Cute Puppy" /> I hope that you have a great summer in $city. $other <br /></h3>' HERE; } ?> </body> </html> Edited June 18, 2013 by webdevdea Quote Link to comment https://forums.phpfreaks.com/topic/279305-help-with-form/ Share on other sites More sharing options...
Solution Barand Posted June 18, 2013 Solution Share Posted June 18, 2013 You already have a current topic on this problem - http://forums.phpfreaks.com/topic/279246-help-with-my-form/ - don't double post. Quote Link to comment https://forums.phpfreaks.com/topic/279305-help-with-form/#findComment-1436587 Share on other sites More sharing options...
ginerjm Posted June 18, 2013 Share Posted June 18, 2013 Your final test of chkerrors is incorrect. == As for the whole logic - you set chkerrors to true if any one of the values is present. Then at the end you are looking to see if chkerrors is false. Your handling of this obviates the need to even have $chkerrors at all. Plus - you output an error message AND a link for every error. You could end up with a rather silly looking page having 4-5 error messages with the same link repeated 4-5 times. If I may offer a re-design: To make it easier to follow, I'd use a var called $no_errors and set it to true to start. I'd also initialize $errmsg to ''. Then as I checked each value, if it was invalid I would set $no_errors to false and add an error message to $errmsg. ($errmsg .= "this field is bad<br>";) When I finished checking each value I would then check if $no_errors was still true. If not I would then echo $errmsg and the <a> tag and exit. Quote Link to comment https://forums.phpfreaks.com/topic/279305-help-with-form/#findComment-1436592 Share on other sites More sharing options...
webdevdea Posted June 18, 2013 Author Share Posted June 18, 2013 not really sure where to put the errmsg you were talking about I have this working except when the user fills in the fields it does not generate the form Your final test of chkerrors is incorrect. == As for the whole logic - you set chkerrors to true if any one of the values is present. Then at the end you are looking to see if chkerrors is false. Your handling of this obviates the need to even have $chkerrors at all. Plus - you output an error message AND a link for every error. You could end up with a rather silly looking page having 4-5 error messages with the same link repeated 4-5 times. If I may offer a re-design: To make it easier to follow, I'd use a var called $no_errors and set it to true to start. I'd also initialize $errmsg to ''. Then as I checked each value, if it was invalid I would set $no_errors to false and add an error message to $errmsg. ($errmsg .= "this field is bad<br>";) When I finished checking each value I would then check if $no_errors was still true. If not I would then echo $errmsg and the <a> tag and exit. <?php $fName = filter_input(INPUT_POST, "fName"); $lName = filter_input(INPUT_POST, "lName"); $city = filter_input(INPUT_POST, "city"); $state = filter_input(INPUT_POST, "state"); $zipCode = filter_input(INPUT_POST, "zipCode"); $other = filter_input(INPUT_POST, "other"); $errmsg = ''; $no_errors = TRUE; if(!empty($_POST['fName'])) { $no_errors = FALSE; } else { echo '***FIRST NAME FIELD REQUIRED*****'; } if(!empty($_POST['lName'])) { $no_errors = FALSE; } else { echo '****LAST NAME FIELD REQUIRED*****'; } if(!empty($_POST['city']) && isset($_POST['city'])) { $no_errors = FALSE; } else { echo '****CITY FIELD REQUIRED*****'; } if(!empty($_POST['state'])) { $no_errors = FALSE; } else { echo '***STATE NAME FIELD REQUIRED*****'; } if(!empty($_POST['zipCode'])) { $no_errors = FALSE; } else { echo '****ZIPCODE FIELD REQUIRED*****'; } if(!empty($_POST['other'])) { $no_errors = FALSE; } else { echo '****TEXT FIELD REQUIRED*****'; } if ($no_errors = TRUE) { echo "<br> <a href='Assignment3.html'>Go back to form</a>"; } else if ($no_errors == FALSE) { echo "Hi there, $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year. <br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br /> I hope that you have a great summer in $city. $other <br />" ; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/279305-help-with-form/#findComment-1436601 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.