simcoweb Posted October 25, 2006 Share Posted October 25, 2006 I have this form script (below) that doesn't produce any errors but does not display any validation errors nor sends the data nor displays the confirmation message. Basically it displays the header/footer and the rest is blank. I don't see the point where it's breaking down. [code]<?php// do the security checkif (isset($_POST['submit'])) {// clean and check form inputs including the secure image code $name = trim(strip_tags($_POST['name'])); $location = trim(strip_tags($_POST['location'])); $email = trim(strip_tags($_POST['email'])); $phone = trim(strip_tags($_POST['phone'])); $best_time = trim(strip_tags($_POST['best_time'])); $details = trim(strip_tags($_POST['details'])); $referred_by = trim(strip_tags($_POST['ref_by'])); $secure = strtoupper(trim(strip_tags($_POST['secure']))); $match = $_SESSION['secure']; // the code on the image}$err = "";include 'header.php';// input error checking if ($name=="") { $err.= "Please provide your name. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if ($location=="") { $err.= "Please provide your city of residence. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if (!$email) { $err.= "Please provide your email address. <a href=\"javascript: history.go(-1)\">Back</a><br>"; } if ($email) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $err.= $email. " is not a valid email address. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } } if ($phone=="") { $err.= "Please provide a phone number. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if ($best_time=="") { $err.= "Please provide the best time to contact you. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if (!$secure) { $err.= "No security code entered. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if (($secure!=$match) && ($secure!="")) { $err.= "Security code mismatch. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if ($err=="") {// set mail variables$to="admin@plateauprofessionals.com";$subject="Plateau Professionals Inquiry";$mailContent="--------CONTACT--------\n" ."Name: ".$name."\n" ."Location: ".$location."\n" ."E-mail: ".$email."\n\n--------PHONE--------\n" ."Phone: ".$phone."\n" ."Best time to call: ".$best_time."\n\n--------Details--------\n" ."Details: ".$details."\n" ."Referred by: ".$referred_by."\n";// send the resultsmail($to, $subject, $mailContent, "From:$email") or print "Could not send email";echo "<h2>Message Sent</h2><br>\n";echo "<font class='bodytext'><blockquote>Your message has been sent. A representative will respond as soon as possible. Thank you for contacting Plateau Professionals!</blockquote><br>\n";}include 'footer.php';?>[/code]The form is at [url=http://www.plateauprofessionals.com/gencontact.php]www.plateauprofessionals.com/gencontact.php[/url]It's fairly basic with the exception of the CAPTCHA image and has action="sendform.php" which is the script code shown. Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/ Share on other sites More sharing options...
gmwebs Posted October 25, 2006 Share Posted October 25, 2006 Debug your $err variable. It will only perform the mailing part of your script if $err is empty. Perhaps it isn't?[code]<?php$err = "";include 'header.php';// input error checking if ($name=="") { $err.= "Please provide your name. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if ($location=="") { $err.= "Please provide your city of residence. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if (!$email) { $err.= "Please provide your email address. <a href=\"javascript: history.go(-1)\">Back</a><br>"; } if ($email) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $err.= $email. " is not a valid email address. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } } if ($phone=="") { $err.= "Please provide a phone number. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if ($best_time=="") { $err.= "Please provide the best time to contact you. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if (!$secure) { $err.= "No security code entered. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; } if (($secure!=$match) && ($secure!="")) { $err.= "Security code mismatch. <a href=\"javascript: history.go(-1)\">Back</a><br/>"; }echo $err;exit(); //this will exit the script allowing you to see the value of $err?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114288 Share on other sites More sharing options...
simcoweb Posted October 25, 2006 Author Share Posted October 25, 2006 heh...silly me. I forgot to put an echo statement to show the various errors. Guess I thought they'd somehow magically appear. ;DOnly challenge left is the security image. For some reason it's not matching it and continually says the security code entry doesn't match. I KNOW i'm typing them in correctly. See anything in that segment that stands out? Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114305 Share on other sites More sharing options...
.josh Posted October 25, 2006 Share Posted October 25, 2006 first thing that stands out to me is this:$match = $_SESSION['secure']; // the code on the imagei don't see a session_start(); at the beginning of your script, so $match is not being set to anything. Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114311 Share on other sites More sharing options...
simcoweb Posted October 25, 2006 Author Share Posted October 25, 2006 Funny you should mention that as i'd just put that in there before receiving your post email. I've added it but it still provides a mismatch error.My revised code looks like this now:[code]<?phpsession_start();// do the security checkif (isset($_POST['submit'])) {// clean and check form inputs including the secure image code $name = trim(strip_tags($_POST['name'])); $location = trim(strip_tags($_POST['location'])); $email = trim(strip_tags($_POST['email'])); $phone = trim(strip_tags($_POST['phone'])); $best_time = trim(strip_tags($_POST['best_time'])); $details = trim(strip_tags($_POST['details'])); $referred_by = trim(strip_tags($_POST['ref_by'])); $secure = strtoupper(trim(strip_tags($_POST['secure']))); $match = $_SESSION['secure']; // the code on the image}$err = "";include 'header.php';// input error checking if ($name=="") { $err.= "Please provide your name. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>"; } if ($location=="") { $err.= "Please provide your city of residence. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>"; } if (!$email) { $err.= "Please provide your email address. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br>"; } if ($email) { if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) { $err.= $email. " is not a valid email address. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>"; } } if ($phone=="") { $err.= "Please provide a phone number. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>"; } if ($best_time=="") { $err.= "Please provide the best time to contact you. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>"; } if (!$secure) { $err.= "No security code entered. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>"; } if (($secure!=$match) && ($secure!="")) { $err.= "Security code mismatch. <a class='body' href=\"javascript: history.go(-1)\">Back To Form</a><br/>"; } //echo $err;//exit; if ($err!='') { echo "<center>"; echo "<strong>Form Error(s)</strong><br/>"; echo "<font class='bodytext'>The following fields were not completed correctly. Please return to the form and complete them accordingly.<br>\n"; echo "<font color='#cc3300'>". nl2br($err). "</font><br/>\n"; echo "</center>";} else {// set mail variables$to="admin@plateauprofessionals.com";$subject="Plateau Professionals Inquiry";$mailContent="--------CONTACT--------\n" ."Name: ".$name."\n" ."Location: ".$location."\n" ."E-mail: ".$email."\n\n--------PHONE--------\n" ."Phone: ".$phone."\n" ."Best time to call: ".$best_time."\n\n--------Details--------\n" ."Details: ".$details."\n" ."Referred by: ".$referred_by."\n";// send the resultsmail($to, $subject, $mailContent, "From:$email") or print "Could not send email";echo "<h2>Message Sent</h2><br>\n";echo "<font class='bodytext'><blockquote>Your message has been sent. A representative will respond as soon as possible. Thank you for contacting Plateau Professionals!</blockquote><br>\n";}include 'footer.php';?>[/code]The form input for the security image is basic stuff:[quote]<td><img src="captcha_image.php" alt="security image" border="0"/></td> </tr> <tr> <td><p align="right"><font class="bodytext">Verification:</font><br><font size="1">Enter the code shown.</font> </p></td> <td><input type="text" name="secure" maxlength="8"></td>[/quote]Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114313 Share on other sites More sharing options...
simcoweb Posted October 25, 2006 Author Share Posted October 25, 2006 Ok, got it to work by adding this to the sessions:[code]<?phpsession_start();session_register("secure");?>[/code]Which then matches the variable match for $_SESSION in the validation process. Form produced no errors and I received the email from the contact form.Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114319 Share on other sites More sharing options...
.josh Posted October 25, 2006 Share Posted October 25, 2006 umm i think that's more of a bandaid than a fix...echo out $match see if it contains something Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114324 Share on other sites More sharing options...
simcoweb Posted October 25, 2006 Author Share Posted October 25, 2006 It echoes the security code. Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114328 Share on other sites More sharing options...
.josh Posted October 25, 2006 Share Posted October 25, 2006 what about before you added that session_register stuff Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114332 Share on other sites More sharing options...
simcoweb Posted October 25, 2006 Author Share Posted October 25, 2006 It echoes nothing if I remove the session lines.Actually i've removed the session_register lines and just having session_start(); on both the form page and the parsing script makes it work. Quote Link to comment https://forums.phpfreaks.com/topic/25074-form-script-doesnt-show-any-errors-but-doesnt-work-either/#findComment-114334 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.