javascript - Google Recaptcha (Contact Still Send Through) -


i having issue contact page , appreciated me google recaptcha coding.

i have added scripts , keys html. showing in website contact page stills goes through if did not click on recaptcha. know java script passing through recaptcha. below html code, javascript , php codings. hope can let me know went wrong.

html code:

<div class="col-md-6 col-md-6">                     <h3 class="title">contact form</h3>                     <p class="form-message"></p>                     <div class="contact-form">                         <!-- form begins -->                         <form role="form" name="contactform" id="contactform" method="post" action="php/contact-form-recaptcha.php">                             <div class="row">                                 <div class="col-md-6">                                     <!-- field 1 -->                                     <div class="input-text form-group">                                         <input type="text" name="contact_name" class="input-name form-control"                                         placeholder="full name" />                                     </div>                                 </div>                                 <div class="col-md-6">                                     <!-- field 2 -->                                     <div class="input-email form-group">                                         <input type="email" name="contact_email" class="input-email form-control"                                         placeholder="email" />                                     </div>                                 </div>                             </div>                             <!-- field 3 -->                             <div class="input-email form-group">                                 <input type="text" name="contact_phone" class="input-phone form-control" placeholder="phone" />                             </div>                             <!-- field 4 -->                             <div class="textarea-message form-group">                                 <textarea name="contact_message" class="textarea-message form-control" placeholder="message"                                 rows="6"></textarea>                             </div></div>                             <!-- captcha box -->                             <div class="g-recaptcha" data-sitekey="6************************************z"></div>                             <!-- button -->                             <button class="btn btn-default" type="submit">send                              <i class="icon-paper-plane"></i></button>                         </form>                         <!-- form ends -->                     </div> 

javascript (this javascript passing through recaptcha if fields filled):

/* ---------------------         contact form   /* --------------------- */ simplecontactform: function(){       if ( $( "#contactform" ).length !== 0 ) {     $('#contactform').bootstrapvalidator({             container: 'tooltip',             feedbackicons: {                 valid: 'fa fa-check',                 warning: 'fa fa-user',                 invalid: 'fa fa-times',                 validating: 'fa fa-refresh'             },             fields: {                  contact_name: {                     validators: {                         notempty: {                             message: ''                         }                     }                 },                 contact_email: {                     validators: {                         notempty: {                             message: ''                         },                         emailaddress: {                             message: ''                         },                         regexp: {                                 regexp: '^[^@\\s]+@([^@\\s]+\\.)+[^@\\s]+$',                                 message: 'the value not valid email address'                         }                     }                 },                 contact_phone: {                     validators: {                         notempty: {                             message: ''                         }                     }                 },                 contact_message: {                     validators: {                         notempty: {                             message: ''                         }                     }                 },             }         })           .on('success.form.bv', function(e) {             e.preventdefault();             var $form        = $(e.target),             validator    = $form.data('bootstrapvalidator'),             submitbutton = validator.getsubmitbutton();             var form_data = $('#contactform').serialize();             $.ajax({                     type: "post",                     datatype: 'json',                     url: "../php/contact-form-recaptcha.php",                                        data: form_data,                     success: function(msg){                                              $('.form-message').html(msg.data);                         $('.form-message').show();                         submitbutton.removeattr("disabled");                         resetform($('#contactform'));                                            },                     error: function(msg){}              });             return false;         });     }     function resetform($form) {          $form.find(                 'input:text, input:password, input, input:file, select, textarea'             )             .val('');          $form.find('input:radio, input:checkbox')             .removeattr('checked')             .removeattr('selected');         $form.find('button[type=submit]')             .attr("disabled", "disabled");      } }, 

php (contact-form-recaptcha.php):

<?php     if(isset($_post['submit']) && !empty($_post['submit'])):     if(isset($_post['g-recaptcha-response']) && !empty($_post['g-recaptcha-response'])):     //your site secret key     $secret = '6*****************************u';     //get verify response data     $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):         //contact form submission code         $to_email = "testing@testing.com"; // email address form data sent         $subject = "contact request"; // subject of email sent         $thanks_page = "index.html"; // path thank page following successful form submission         $contact_page = "index.html"; // path html contact page form appears          $nam = strip_tags($_post["contact_name"]);         $ema = strip_tags($_post["contact_email"]);         $pho = strip_tags($_post["contact_phone"]);         $com = strip_tags($_post["contact_message"]);          // set content-type when sending html email         $headers = "mime-version: 1.0" . "\r\n";         $headers .= "content-type:text/html;charset=utf-8" . "\r\n";         // more headers         $headers .= 'from:'.$nam.' <'.$ema.'>' . "\r\n";         //send email         $email_body =          "<strong>from: </strong>" . $nam . "<br />         <strong>email: </strong>" . $ema . "<br />           <strong>phone: </strong>" . $pho . "<br />           <strong>message: </strong>" . $com;          $succmsg = 'your contact request have submitted successfully.';     else:         $errmsg = 'robot verification failed, please try again.';     endif; else:     $errmsg = 'please click on recaptcha box.'; endif; else: $errmsg = ''; $succmsg = ''; endif; ?> 

please me... million...

if want check if user clicked on i'm not robot checkbox, can use .getresponse() function provided recaptcha api.

it return empty string in case user did not validate himself, this:

if(grecaptcha.getresponse() == "")     alert("you can't proceed!"); else     alert("thank you"); 

in case user has validated himself, response long string.

more api can found on page: recaptcha javascript api


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -