bizstorm Posted December 5, 2019 Share Posted December 5, 2019 Hi All. New at this, form is working perfect, then added recapthca, now it only handles recaptcha and not the form. not sure where the error is Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/ Share on other sites More sharing options...
cyberRobot Posted December 5, 2019 Share Posted December 5, 2019 For future reference, it's better to post the actual code versus screenshots of the code. That way we don't need to retype things if we're interested in testing out the code. Looking at the last screenshot above, it seems like you have some smart quotes in some of the lines of code. For example, the second line has smart quotes in the $POST variable. The same goes for the next line where you are setting the value for $errMsg. Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572236 Share on other sites More sharing options...
bizstorm Posted December 5, 2019 Author Share Posted December 5, 2019 (edited) Hi Thanks for the response and any inconvenience, please find below <?php if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])) if(empty($_POST[‘g-recaptcha-response’])){ $errMsg = ‘Please check the robot checkbox.’; } else if(isset($_POST[‘g-recaptcha-response’]) && !empty($_POST[‘g-recaptcha-response’])) { $secret = '6LcRNsUUAAAAAEap2oQ-wjTO2hmJoDC_OLlWoA29'; $verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$_POST['g-recaptcha-response']); $responseData = json_decode($verifyResponse); if($responseData->success) { $succMsg = 'Your contact request have submitted successfully.'; } else { $errMsg = 'Robot verification failed, please try again.'; } } if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "info@globalforcesecurity.co.za"; $email_subject = "Online Contact Form"; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['first_name']) || !isset($_POST['last_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['first_name']; // required $last_name = $_POST['last_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The First Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$last_name)) { $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($first_name)."\n"; $email_message .= "Last Name: ".clean_string($last_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> header("Location: contact-thank-you.html"); Thank you for contacting us. We will be in touch with you very soon. <?php } ?> Edited December 5, 2019 by bizstorm Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572237 Share on other sites More sharing options...
Strider64 Posted December 5, 2019 Share Posted December 5, 2019 Well I would check the captcha first then process the email. Here's my little script that does that -> /* The Following to get response back from Google recaptcha */ $url = "https://www.google.com/recaptcha/api/siteverify"; $remoteServer = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_SANITIZE_URL); $response = file_get_contents($url . "?secret=" . PRIVATE_KEY . "&response=" . \htmlspecialchars($_POST['g-recaptcha-response']) . "&remoteip=" . $remoteServer); $recaptcha_data = json_decode($response); /* The actual check of the recaptcha */ if (isset($recaptcha_data->success) && $recaptcha_data->success === TRUE) { $success = "Mail was sent!"; $data['name'] = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['email'] = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL); $data['phone'] = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['website'] = filter_input(INPUT_POST, 'website', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['reason'] = filter_input(INPUT_POST, 'reason', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $data['comments'] = filter_input(INPUT_POST, 'comments', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $send = new Email($data); } else { $success = "You're not a human!"; // Not of a production server: } The $send = new Email($data) is my email process, if your form was working before then just do something like that. Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572238 Share on other sites More sharing options...
bizstorm Posted December 5, 2019 Author Share Posted December 5, 2019 Thanks will check now Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572239 Share on other sites More sharing options...
cyberRobot Posted December 5, 2019 Share Posted December 5, 2019 20 minutes ago, bizstorm said: ...please find below Did you see the other part of my response? You will need to replace the smart quotes in lines like the following: $errMsg = ‘Please check the robot checkbox.’; Smart quotes will cause an HTTP 500 error. The above line should look like this $errMsg = 'Please check the robot checkbox.'; Note that the quotes are straight versus curly. Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572240 Share on other sites More sharing options...
cyberRobot Posted December 5, 2019 Share Posted December 5, 2019 Side note: you'll want to look into getting a new secret key for reCAPTCHA before going live with your script. The key isn't exactly secret with it being posted here. More information about the key can be found here:https://developers.google.com/recaptcha/intro Quote The secret key needs to be kept safe for security purposes. Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572241 Share on other sites More sharing options...
bizstorm Posted December 5, 2019 Author Share Posted December 5, 2019 Noted Thanks, made the changes, working but not taking me to my thank you page Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572242 Share on other sites More sharing options...
bizstorm Posted December 5, 2019 Author Share Posted December 5, 2019 Got it. I wish to thank you for the help 😂 Quote Link to comment https://forums.phpfreaks.com/topic/309632-unable-to-handle-the-page/#findComment-1572243 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.