custom24burst Posted February 14, 2023 Share Posted February 14, 2023 Hi All Not really my area of expertise, so I am hoping someone can help me - I was asked to add a V2 reCaptcha to a form previously built by another developer. I have followed many threads but the form will still send without the need to check the Robot box.... clearly I have missed something. If anyone can shed some light I would be extremely grateful. http://interclad.co.uk/2014/contacts-test.php Quote Link to comment https://forums.phpfreaks.com/topic/315911-recaptcha-not-validating/ Share on other sites More sharing options...
mac_gyver Posted February 14, 2023 Share Posted February 14, 2023 you need to post all the code in the forum, using the forum's <> menu button. redact any sensitive information, such as the recpatcha private key. Quote Link to comment https://forums.phpfreaks.com/topic/315911-recaptcha-not-validating/#findComment-1605637 Share on other sites More sharing options...
custom24burst Posted February 14, 2023 Author Share Posted February 14, 2023 Thanks - First up - form page <!DOCTYPE html> <html lang="en"> <head> <title>Contacts</title> <meta charset="utf-8"> <meta HTTP-EQUIV="Pragma" CONTENT="no-cache"> <meta HTTP-EQUIV="Expires" CONTENT="-1"> <link rel="stylesheet" href="iealert/style.css"> <link rel="stylesheet" href="Main.css"> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script src="superfish.js"></script> <script src="iealert.js"></script> <script> jQuery(document).ready(function () { jQuery('ul.sf-menu').superfish(); $("body").iealert(); $("#inputs").focus(function() { $(this).addClass("inputSelected"); }); }); </script> <script LANGUAGE="JavaScript"> function validateFormOnSubmit(theForm) { var reason = ""; reason += validateUsername(theForm.name); reason += validateEmail(theForm.email); reason += validatePhone(theForm.phone); reason += validateEmpty(theForm.message); if (reason != "") { alert("Some fields need correction:\n" + reason); return false; } return true; } function validateEmpty(fld) { var error = ""; if (fld.value.length == 0) { fld.style.background = '#DDEBF4'; error = "The required field has not been filled in.\n" } else { fld.style.background = 'White'; } return error; } function validateUsername(fld) { var error = ""; var illegalChars = /\W/; // allow letters, numbers, and underscores if (fld.value == "") { fld.style.background = '#DDEBF4'; error = "You didn't enter a username.\n"; } else { fld.style.background = 'White'; } return error; } function trim(s) { return s.replace(/^\s+|\s+$/, ''); } function validateEmail(fld) { var error=""; var tfld = trim(fld.value); // value of field with whitespace trimmed off var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ; var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ; if (fld.value == "") { fld.style.background = '#DDEBF4'; error = "You didn't enter an email address.\n"; } else if (!emailFilter.test(tfld)) { //test email for illegal characters fld.style.background = '#DDEBF4'; error = "Please enter a valid email address.\n"; } else if (fld.value.match(illegalChars)) { fld.style.background = '#DDEBF4'; error = "The email address contains illegal characters.\n"; } else { fld.style.background = 'White'; } return error; } function validatePhone(fld) { var error = ""; var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, ''); if (fld.value == "") { error = "You didn't enter a phone number.\n"; fld.style.background = '#DDEBF4'; } else if (isNaN(parseInt(stripped))) { error = "The phone number contains illegal characters.\n"; fld.style.background = '#DDEBF4'; } return error; } function resetcolor(thecontrol) { thecontrol.style.background = 'White'; } function resetForm(){ document.getElementById("name").style.background = 'White'; document.getElementById("phone").style.background = 'White'; document.getElementById("email").style.background = 'White'; document.getElementById("message").style.background = 'White'; document.getElementById("name").value = ''; document.getElementById("companyname").value = ''; document.getElementById("phone").value = ''; document.getElementById("email").value = ''; document.getElementById("message").value = ''; } </script> <script src='https://www.google.com/recaptcha/api.js' async defer></script> <!--[if lt IE 8]> <div style=' clear: both; text-align:center; position: relative;'> <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode"> <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /> </a> </div> <![endif]--> <!--[if lt IE 9]> <script src="js/html5shiv.js"></script> <link rel="stylesheet" media="screen" href="css/ie.css"> <![endif]--> </head> <body class="" id="top"> <header> <div class="header_top"> <!--==============================header=================================--> <div class="container_12"> <div class="container_12"> <div class="grid_12"> <h1> <a href="index.html"> <img src="images/logo.png" alt="Your Happy Family"> </a> </h1> <div class="menu_block "> <nav class="horizontal-nav full-width horizontalNav-notprocessed"> <ul class="sf-menu"> <!-- <li class="current"><a href="index.html">Home</a></li>--> <li><a href="products.html">Products</a> <ul> <li><a href="caterclad.html">Caterclad®</a></li> <li><a href="mediclad.html">Mediclad®</a></li> <li><a href="interlock.html">Interlock™</a></li> <li><a href="polyclad.html">Polyclad</a></li> <li><a href="adhesives.html">Adhesives</a></li> <li><a href="accessories.html">Accessories</a></li> <li><a href="colors.html">COLOURS</a></li> <li><a href="cocktail.html">Cocktail</a></li> <li><a href="matting.html">Gradus </a> <ul> <li><a href="matting.html">Gradus Matting </a></li> <li><a href="walls.html">Gradus Walls </a></li> <li><a href="carpets.html">Gradus Carpets </a></li> </ul> </li> </ul> </li> <li><a href="flooring.html">Flooring</a></li> <li><a href="downloads.html">Downloads</a></li> <li><a href="contacts.html">Contacts</a></li> <li><a href="gallery.html">Gallery</a></li> </ul> </nav> <div class="clear"></div> </div> </div></div> </div> </div> </header> <!--==============================Content=================================--> <div class="content"> <div class="container_12"> <div class="grid_8"> <h3>Contact Us</h3> <!-- status message --> <?php if(!empty($statusMsg)){ ?> <p class="status-msg <?php echo $status; ?>"><?php echo $statusMsg; ?></p> <?php } ?> <form name="contact" method="post" action="SendEnquiry.php"> <table width="100%"> <tr> <td></td> <td><font size="2px"><i>All (*) fields are required</i></font></td> </tr> <tr> <td>Name *</td> <td> <input type="text" id="name" name="name" onfocus="resetcolor(this)" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>Company</td> <td> <input type="text" name="companyname" id="companyname" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>E-mail *</td> <td> <input type="text" name="email" id="email" onfocus="resetcolor(this)" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>Phone *</td> <td> <input type="text" name="phone" id="phone" onfocus="resetcolor(this)" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>Message *</td> <td> <textarea id="message" name="message" cols="30" rows="5" onfocus="resetcolor(this)" style="width:90%" class="inputs"></textarea> </td> </tr> <tr height="10"> <td colspan="2"></td> </tr> <tr> <td colspan="2" style="text-align:center"> <div class="g-recaptcha" data-sitekey="xxx-----KEY---XXX" align="center"></div> <input type="submit" value="Send" class="more"/> <input type="button" value="Clear" class="more" onClick="resetForm()"/> </td> </tr> </table> </form><br /><br /> <iframe width="100%" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=TN16+3JR&sll=51.301428,0.006695&sspn=0.055595,0.154152&ie=UTF8&hq=&hnear=Biggin+Hill+TN16+3JR,+United+Kingdom&t=m&z=14&ll=51.312894,0.034113&output=embed"></iframe> </div> <div class="grid_4"> <h3></h3> <table width="100%" style="text-align:left;"> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® (UK) Ltd</span><br />173 Main Road <br />Biggin Hill <br />Kent <br />TN16 3JR <br />Tel: 01959 572447 <br />Fax: 01959 576974<br /> <a href="mailto:sales@interclad.co.uk">sales@interclad.co.uk</a><br /><br /> </td> </tr> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® Scotland</span><br />Newmount House <br/>Thomson Avenue <br />Johnstone <br />PA5 8SU <br />Tel: 01505 328424 <br />Fax: 01505 346661<br /> <a href="mailto:interclad.scotland@ntlworld.com">interclad.scotland@ntlworld.com</a><br /><br /> </td> </tr> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® Ireland</span><br /> Unit 1 Metro Business Park <br />Ballycureen<br /> Cork<br /> Ireland <br />Tel: 021 496 5117<br />Fax: 021 496 5112<br /> <a href="mailto:interclad@eircom.net">interclad@eircom.net</a><br /><br /> </td> </tr> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® Wales</span><br />173 Main Road <br />Biggin Hill <br />Kent <br />TN16 3JR <br />Tel: 01959 572447 <br />Fax: 01959 576974<br /> <a href="mailto:sales@interclad.co.uk">sales@interclad.co.uk</a> </td> </tr> </table> </div> </div> </div> <!--==============================footer=================================--> <footer> <div class="container_12"> <div class="grid_12"> <div class="copy"> <center><p>The information on this site is to the best of our knowledge accurate and true. We are unable to accept responsibility in respect of factors which are outside our knowledge and control. In keeping with Interclad®'s policy of continuous product development specifications may change without notice. Changes will only improve the specification of our products. Products can be selected to help meet guidelines of Approved Document M (ADM) and the Equality Act (DDA).</p> <p>Caterclad® Waterfield® Interclad® Cladfix® Mediclad® Interlock™ Softwall™ SuperBond™ are Trade Marks of Interclad® Limited.</p></center> </div> </div> </div> </footer> </body> </html> ---------------------------------------------------------------------------------------------------------------------------------------------- Secondly - form.php <?php $subject = $_POST['subject']; $category = $_POST['category']; $message = $_POST['message']; // Ensure that recaptchabox is not empty if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ $secretKey = 'XXX---KEY---XXX'; // send request and Verify the reCAPTCHA via g_recaptcha_response post parameter. $verifyRequest = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response']); $result = json_decode($verifyRequest); // Check if captcha entered is valid if($result->success){ // send your form data and update database echo "<script> alert('Thank you for your enquiry - a team member will contact you shortly')</script>"; }else{ echo "<script> alert('Please prove you are not a robot')</script>"; } }else{ echo "Recaptcha box cannot be empty"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/315911-recaptcha-not-validating/#findComment-1605643 Share on other sites More sharing options...
Barand Posted February 14, 2023 Share Posted February 14, 2023 2 hours ago, mac_gyver said: you need to post all the code in the forum, using the forum's <> menu button. ^ You were told to use the "code" button I have edited it for you this time. Quote Link to comment https://forums.phpfreaks.com/topic/315911-recaptcha-not-validating/#findComment-1605645 Share on other sites More sharing options...
custom24burst Posted February 14, 2023 Author Share Posted February 14, 2023 <!DOCTYPE html> <html lang="en"> <head> <title>Contacts</title> <meta charset="utf-8"> <meta HTTP-EQUIV="Pragma" CONTENT="no-cache"> <meta HTTP-EQUIV="Expires" CONTENT="-1"> <link rel="stylesheet" href="iealert/style.css"> <link rel="stylesheet" href="Main.css"> <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> <script src="superfish.js"></script> <script src="iealert.js"></script> <script> jQuery(document).ready(function () { jQuery('ul.sf-menu').superfish(); $("body").iealert(); $("#inputs").focus(function() { $(this).addClass("inputSelected"); }); }); </script> <script LANGUAGE="JavaScript"> function validateFormOnSubmit(theForm) { var reason = ""; reason += validateUsername(theForm.name); reason += validateEmail(theForm.email); reason += validatePhone(theForm.phone); reason += validateEmpty(theForm.message); if (reason != "") { alert("Some fields need correction:\n" + reason); return false; } return true; } function validateEmpty(fld) { var error = ""; if (fld.value.length == 0) { fld.style.background = '#DDEBF4'; error = "The required field has not been filled in.\n" } else { fld.style.background = 'White'; } return error; } function validateUsername(fld) { var error = ""; var illegalChars = /\W/; // allow letters, numbers, and underscores if (fld.value == "") { fld.style.background = '#DDEBF4'; error = "You didn't enter a username.\n"; } else { fld.style.background = 'White'; } return error; } function trim(s) { return s.replace(/^\s+|\s+$/, ''); } function validateEmail(fld) { var error=""; var tfld = trim(fld.value); // value of field with whitespace trimmed off var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ; var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ; if (fld.value == "") { fld.style.background = '#DDEBF4'; error = "You didn't enter an email address.\n"; } else if (!emailFilter.test(tfld)) { //test email for illegal characters fld.style.background = '#DDEBF4'; error = "Please enter a valid email address.\n"; } else if (fld.value.match(illegalChars)) { fld.style.background = '#DDEBF4'; error = "The email address contains illegal characters.\n"; } else { fld.style.background = 'White'; } return error; } function validatePhone(fld) { var error = ""; var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, ''); if (fld.value == "") { error = "You didn't enter a phone number.\n"; fld.style.background = '#DDEBF4'; } else if (isNaN(parseInt(stripped))) { error = "The phone number contains illegal characters.\n"; fld.style.background = '#DDEBF4'; } return error; } function resetcolor(thecontrol) { thecontrol.style.background = 'White'; } function resetForm(){ document.getElementById("name").style.background = 'White'; document.getElementById("phone").style.background = 'White'; document.getElementById("email").style.background = 'White'; document.getElementById("message").style.background = 'White'; document.getElementById("name").value = ''; document.getElementById("companyname").value = ''; document.getElementById("phone").value = ''; document.getElementById("email").value = ''; document.getElementById("message").value = ''; } </script> <script src='https://www.google.com/recaptcha/api.js' async defer></script> <!--[if lt IE 8]> <div style=' clear: both; text-align:center; position: relative;'> <a href="http://windows.microsoft.com/en-US/internet-explorer/products/ie/home?ocid=ie6_countdown_bannercode"> <img src="http://storage.ie6countdown.com/assets/100/images/banners/warning_bar_0000_us.jpg" border="0" height="42" width="820" alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today." /> </a> </div> <![endif]--> <!--[if lt IE 9]> <script src="js/html5shiv.js"></script> <link rel="stylesheet" media="screen" href="css/ie.css"> <![endif]--> </head> <body class="" id="top"> <header> <div class="header_top"> <!--==============================header=================================--> <div class="container_12"> <div class="container_12"> <div class="grid_12"> <h1> <a href="index.html"> <img src="images/logo.png" alt="Your Happy Family"> </a> </h1> <div class="menu_block "> <nav class="horizontal-nav full-width horizontalNav-notprocessed"> <ul class="sf-menu"> <!-- <li class="current"><a href="index.html">Home</a></li>--> <li><a href="products.html">Products</a> <ul> <li><a href="caterclad.html">Caterclad®</a></li> <li><a href="mediclad.html">Mediclad®</a></li> <li><a href="interlock.html">Interlock™</a></li> <li><a href="polyclad.html">Polyclad</a></li> <li><a href="adhesives.html">Adhesives</a></li> <li><a href="accessories.html">Accessories</a></li> <li><a href="colors.html">COLOURS</a></li> <li><a href="cocktail.html">Cocktail</a></li> <li><a href="matting.html">Gradus </a> <ul> <li><a href="matting.html">Gradus Matting </a></li> <li><a href="walls.html">Gradus Walls </a></li> <li><a href="carpets.html">Gradus Carpets </a></li> </ul> </li> </ul> </li> <li><a href="flooring.html">Flooring</a></li> <li><a href="downloads.html">Downloads</a></li> <li><a href="contacts.html">Contacts</a></li> <li><a href="gallery.html">Gallery</a></li> </ul> </nav> <div class="clear"></div> </div> </div></div> </div> </div> </header> <!--==============================Content=================================--> <div class="content"> <div class="container_12"> <div class="grid_8"> <h3>Contact Us</h3> <!-- status message --> <?php if(!empty($statusMsg)){ ?> <p class="status-msg <?php echo $status; ?>"><?php echo $statusMsg; ?></p> <?php } ?> <form name="contact" method="post" action="SendEnquiry.php"> <table width="100%"> <tr> <td></td> <td><font size="2px"><i>All (*) fields are required</i></font></td> </tr> <tr> <td>Name *</td> <td> <input type="text" id="name" name="name" onfocus="resetcolor(this)" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>Company</td> <td> <input type="text" name="companyname" id="companyname" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>E-mail *</td> <td> <input type="text" name="email" id="email" onfocus="resetcolor(this)" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>Phone *</td> <td> <input type="text" name="phone" id="phone" onfocus="resetcolor(this)" style="width:90%" class="inputs"/> </td> </tr> <tr> <td>Message *</td> <td> <textarea id="message" name="message" cols="30" rows="5" onfocus="resetcolor(this)" style="width:90%" class="inputs"></textarea> </td> </tr> <tr height="10"> <td colspan="2"></td> </tr> <tr> <td colspan="2" style="text-align:center"> <div class="g-recaptcha" data-sitekey="xxx-----KEY---XXX" align="center"></div> <input type="submit" value="Send" class="more"/> <input type="button" value="Clear" class="more" onClick="resetForm()"/> </td> </tr> </table> </form><br /><br /> <iframe width="100%" height="400" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.co.uk/maps?f=q&source=s_q&hl=en&geocode=&q=TN16+3JR&sll=51.301428,0.006695&sspn=0.055595,0.154152&ie=UTF8&hq=&hnear=Biggin+Hill+TN16+3JR,+United+Kingdom&t=m&z=14&ll=51.312894,0.034113&output=embed"></iframe> </div> <div class="grid_4"> <h3></h3> <table width="100%" style="text-align:left;"> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® (UK) Ltd</span><br />173 Main Road <br />Biggin Hill <br />Kent <br />TN16 3JR <br />Tel: 01959 572447 <br />Fax: 01959 576974<br /> <a href="mailto:sales@interclad.co.uk">sales@interclad.co.uk</a><br /><br /> </td> </tr> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® Scotland</span><br />Newmount House <br/>Thomson Avenue <br />Johnstone <br />PA5 8SU <br />Tel: 01505 328424 <br />Fax: 01505 346661<br /> <a href="mailto:interclad.scotland@ntlworld.com">interclad.scotland@ntlworld.com</a><br /><br /> </td> </tr> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® Ireland</span><br /> Unit 1 Metro Business Park <br />Ballycureen<br /> Cork<br /> Ireland <br />Tel: 021 496 5117<br />Fax: 021 496 5112<br /> <a href="mailto:interclad@eircom.net">interclad@eircom.net</a><br /><br /> </td> </tr> <tr> <td> <span style="font-weight:bold;background-color:#497C98; padding:5px; color:White;">Interclad® Wales</span><br />173 Main Road <br />Biggin Hill <br />Kent <br />TN16 3JR <br />Tel: 01959 572447 <br />Fax: 01959 576974<br /> <a href="mailto:sales@interclad.co.uk">sales@interclad.co.uk</a> </td> </tr> </table> </div> </div> </div> <!--==============================footer=================================--> <footer> <div class="container_12"> <div class="grid_12"> <div class="copy"> <center><p>The information on this site is to the best of our knowledge accurate and true. We are unable to accept responsibility in respect of factors which are outside our knowledge and control. In keeping with Interclad®'s policy of continuous product development specifications may change without notice. Changes will only improve the specification of our products. Products can be selected to help meet guidelines of Approved Document M (ADM) and the Equality Act (DDA).</p> <p>Caterclad® Waterfield® Interclad® Cladfix® Mediclad® Interlock™ Softwall™ SuperBond™ are Trade Marks of Interclad® Limited.</p></center> </div> </div> </div> </footer> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/315911-recaptcha-not-validating/#findComment-1605647 Share on other sites More sharing options...
custom24burst Posted February 14, 2023 Author Share Posted February 14, 2023 <?php $subject = $_POST['subject']; $category = $_POST['category']; $message = $_POST['message']; // Ensure that recaptchabox is not empty if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ $secretKey = 'XXX---KEY---XXX'; // send request and Verify the reCAPTCHA via g_recaptcha_response post parameter. $verifyRequest = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret='.$secretKey.'&response='.$_POST['g-recaptcha-response']); $result = json_decode($verifyRequest); // Check if captcha entered is valid if($result->success){ // send your form data and update database echo "<script> alert('Thank you for your enquiry - a team member will contact you shortly')</script>"; }else{ echo "<script> alert('Please prove you are not a robot')</script>"; } }else{ echo "Recaptcha box cannot be empty"; } ?> 9 minutes ago, Barand said: ^ You were told to use the "code" button I have edited it for you this time. Thank you - where do I collect the edit from - I am new here Quote Link to comment https://forums.phpfreaks.com/topic/315911-recaptcha-not-validating/#findComment-1605648 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.