HTML:
<form method="POST" name="contact" class="formContact" id="formContact">
<div class="col-md-12">
<h1><label class="col-md-12"><?php echo $this->lang->line('index_contact_contact'); ?></label></h1>
</div>
<div class="col-md-12"></div>
<label class="col-md-4">*<?php echo $this->lang->line('index_contact_name'); ?>:</label>
<div class="col-md-8">
<input type="text" name="naam" class="form-control" placeholder="<?php echo $this->lang->line('index_contact_yname'); ?>">
</div>
<label class="col-md-4">*<?php echo $this->lang->line('index_contact_email'); ?>:</label>
<div class="col-md-8">
<input type="text" name="email" class="form-control" placeholder="<?php echo $this->lang->line('index_contact_yemail'); ?>">
</div>
<label class="col-md-4"><?php echo $this->lang->line('index_contact_phone'); ?>:</label>
<div class="col-md-8">
<input type="text" name="telefoon" class="form-control" placeholder="<?php echo $this->lang->line('index_contact_yphone'); ?>">
</div>
<label class="col-md-4">*<?php echo $this->lang->line('index_contact_question'); ?>:</label>
<div class="col-md-8">
<textarea id="vragen" name="vraag" style="resize:none" maxlength="500" class="form-control" placeholder="<?php echo $this->lang->line('index_contact_yquestion'); ?>"></textarea>
<p id="teller"></p>
</div>
<div class="col-md-8 col-md-offset-4" style="margin-top:10px;">
<?php
//echo $recaptcha->create_box();
?>
<div class="g-recaptcha"
data-sitekey="......."
data-callback="onCompleted"
data-size="invisible">
</div>
</div>
<div class="col-md-12 text-right inputcontact">
<input type="submit" name="btnSubmit" value="Verstuur" class="btn btn-default">
</div>
<div class="col-md-12">
<label class="col-md-12 inputcontact"><?php echo $this->lang->line('index_contact_required'); ?></label>
</div>
</form>
Javascript (jquery)
$("#formContact").validate({
rules:{
naam:{
required:true,
minlength:2,
maxlength:40,
accept:"[a-z A-Z]+"
},
email:{
required:true,
maxlength:50,
email:true
},
telefoon:{
required:false,
accept:"[0-9 -]+",
maxlength:15
},
vraag:{
required:true
}
},
messages:{
naam:{
minlength:"Dit veld moet minimaal {0} tekens bevatten.",
accept: "Geen cijfers of speciale tekens."
},
telefoon:{
maxlength: "Maximaal {0} tekens",
accept: "alleen cijfers en het scheidingsteken: - "
},
email:{
maxlength: "Dit veld mag maximaal {0} tekens bevatten.",
email:"Dit is geen geldig e-mailadres"
}
}
});
var validationCheck = false;
$("#formContact").submit(function(event) {
if (grecaptcha.getResponse()) {
// 2) finally sending form data
event.submit();
}else{
// 1) Before sending we must validate captcha
grecaptcha.reset();
console.log('validation completed.');
event.preventDefault(); //prevent form submit before captcha is completed
grecaptcha.execute();
}
});
onCompleted = function(response) {
console.log('captcha completed.');
$("#formContact").submit();
return true;
};
PHP
if (isset($_POST['btnSubmit'])) {
die("for testing purposes");
}
question: I'm trying to add a invisible recaptcha to my site, it works but somehow I have the press the submit button twice, once for validation and once for the submit, I only want to press it once to work, when I press the button the first time I get this error: Uncaught (in promise) null
the second one does the thing but I still get this:
Uncaught TypeError: event.submit is not a function
at HTMLFormElement.<anonymous> (contact:301)
at HTMLFormElement.dispatch (VM34 jquery.js:3)
at HTMLFormElement.r.handle (VM34 jquery.js:3)
Could anyone help me with this?