Monday 15 August 2011

php - I want this to validate, if no errors to mail out the answers. -



php - I want this to validate, if no errors to mail out the answers. -

i new php , helping non-profit exit survey of volunteers. have built next script space above first html tag , can show me on submit when field empty not send if right first submit or on resubmission. doing wrong mail service function or error array built wrong? give thanks kindly words of advice.

here php code:

<?php $firstnameerr = $lastnameerr = $q1err = $q2err = $q3err = $q4err = $q5err = $q6err = $q7err = $q8err = $q9err = $q10err = $q11err = $a1err = $a2err = $a3err = $a4err = $a5err = $a6err = $a7err = $a8err = $a9err = $a10err = $a11err = ""; $firstname = $lastname = $q1 = $q2 = $q3 = $q4 = $q5 = $q6 = $q7 = $q8 = $q9 = $q10 = $q11 = $a1 = $a2 = $a3 = $a4 = $a5 = $a6 = $a7 = $a8 = $a9 = $a10 = $a11 = ""; if ($_server["request_method"] == "post") { //here fields checking $firstname = $_post["firstname"]; $lastname = $_post["lastname"]; $q1 = $_post["q1"]; $q2 = $_post["q2"]; $q3 = $_post["q3"]; $q4 = $_post["q4"]; $q5 = $_post["q5"]; $q6 = $_post["q6"]; $q7 = $_post["q7"]; $q8 = $_post["q8"]; $q9 = $_post["q9"]; $q10 = $_post["q10"]; $q11 = $_post["q11"]; $a1 = $_post["a1"]; $a2 = $_post["a2"]; $a3 = $_post["a3"]; $a4 = $_post["a4"]; $a5 = $_post["a5"]; $a6 = $_post["a6"]; $a7 = $_post["a7"]; $a8 = $_post["a8"]; $a9 = $_post["a9"]; $a10 = $_post["a10"]; $a11 = $_post["a11"]; //start of first name validation if (empty($_post["firstname"])) { //note: below post error message $firstnameerr = "your first name required please"; } else { $firstname = $_post["firstname"]; } //start of lastly name validation if (empty($_post["lastname"])) { $lastnameerr = "your lastly name required please"; } else { $lastname = $_post["lastname"]; } //start of question 1 radio button validation if (empty($_post["q1"])) { $q1err = "please select answer"; } else { $q1 = $_post["q1"]; } //start of reply 2 - not validating if (empty($_post["a1"])) { $a1 = ""; } else { $a1 = $_post["a1"]; } //start of question 2 radio button validation if (empty($_post["q2"])) { $q2err = "please select answer"; } else { $q2 = $_post["q1"]; } if (empty($_post["a2"])) { $a2 = ""; } else { $a2 = $_post["a2"]; } if (empty($_post["q3"])) { $q3err = "please select answer"; } else { $q3 = $_post["q3"]; } if (empty($_post["a3"])) { $a3 = ""; } else { $a3 = $_post["a3"]; } if (empty($_post["q4"])) { $q4err = "please select answer"; } else { $q4 = $_post["q4"]; } if (empty($_post["a4"])) { $a4 = ""; } else { $a4 = check_input($_post["a4"]); } if (empty($_post["q5"])) { $q5err = "please select answer"; } else { $q5 = $_post["q5"]; } if (empty($_post["a5"])) { $a5 = ""; } else { $a5 = $_post["a5"]; } if (empty($_post["q6"])) { $q6err = "please select answer"; } else { $q6 = $_post["q6"]; } if (empty($_post["a6"])) { $a6 = ""; } else { $a6 = $_post["a6"]; } if (empty($_post["q7"])) { $q7err = "please select answer"; } else { $q7 = $_post["q7"]; } if (empty($_post["a7"])) { $a7 = ""; } else { $a7 = $_post["a7"]; } if (empty($_post["q8"])) { $q8err = "please select answer"; } else { $q8 = $_post["q8"]; } if (empty($_post["a8"])) { $a8 = ""; } else { $a8 = $_post["a8"]; } if (empty($_post["q9"])) { $q9err = "please select answer"; } else { $q9 = $_post["q9"]; } if (empty($_post["a9"])) { $a9 = ""; } else { $a9 = $_post["a9"]; } if (empty($_post["q10"])) { $q10err = "please select answer"; } else { $q10 = $_post["q10"]; } if (empty($_post["a10"])) { $a10 = ""; } else { $a10 = $_post["a10"]; } if (empty($_post["q11"])) { $q11err = "please select answer"; } else { $q11 = $_post["q11"]; } if (empty($_post["a11"])) { $a11 = ""; } else { $a11 = $_post["a11"]; } //email out results code if ($firstnameerr == "" && $lastnameerr == "" && $q1err == "" && $q2err == ""&& $q3err == "" && $q4err == "" && $q5err == "" && $q6err == "" && $q7err == "" && $q8err == "" && $q9err == "" && $q10err == "" && $q11err == "") { /* send message using mail() function */ mail($myemail, $subject, $message);{ $myemail = "anyone@gmail.com"; $subject = "exit survey completed"; $message = "greetings! exit survey sent out has been completed by: first name: $firstname lastly name: $lastname here $firstname had say: 1: beans? answer: $q1 explaination, if recorded: $a1 2. george wendt? answer: $q2 explaination, if recorded: $a2 3. watch film beans? answer: $q3 explaination, if recorded: $a3 4. watch film george wendt eats beans? answer: $q4 explaination, if recorded: $a4 5. ___ ? answer: $q5 explaination, if recorded: $a5 6. ___ ? answer: $q6 explaination, if recorded: $a6 7. ___ ? answer: $q7 explaination, if recorded: $a7 8. ___ ? answer: $q8 explaination, if recorded: $a8 9. did sense received ongoing feedback on performance? answer: $q9 explaination, if recorded: $a9 10. did sense feedback on performance presented in sensitive , confidential manner? answer: $q10 explaination, if recorded: $a10 11. ___? answer: $q11 explaination, if recorded: $a11 additional comments $firstname : $comments have great day! ______________________________________________________________________________ give thanks you"; /* redirect visitor give thanks page */ header('location: thanks.htm'); exit(); } } ?>

you're calling mail() before setting values you're trying use. reverse that.

$myemail = "anyone@gmail.com"; $subject = "exit survey completed"; $message = "greetings! exit survey sent out has been completed by: ... give thanks you"; mail($myemail, $subject, $message);

php html validation

No comments:

Post a Comment