jquery parsley ajax,jquery - reCaptcha Invisible, parsley and ajax form - Stack Overflow

左丘修齐
2023-12-01

I'll share with you how I got ParsleyJS and Invisible reCaptcha working for me. Below is the code I used. This was POC code only, not production; and I did not do an AJAX post. And please excuse any uglyness, because I had to strip out a lot of fluff:

First Name*

type="text"

id="input-first-name"

name="first-name"

data-parsley-trigger="blur"

data-parsley-error-message="First Name is required"

required>

Last Name*

type="text"

name="last-name"

id="input-last-name"

data-parsley-trigger="blur"

data-parsley-error-message="Last Name is required"

required>

Submit

function onScriptLoad() {

var htmlEl = document.querySelector('.g-recaptcha');

var captchaOptions = {

sitekey: 'Your_Site_Key',

size: 'invisible',

callback: function (token) {

$('.js-validate').submit();

console.log('test: ',token);

}

};

recaptchaId = window.grecaptcha.render(htmlEl, captchaOptions, false);

$('#theSubmitBtn').click(function(e){

e.preventDefault();

if(grecaptcha.getResponse() != ''){

grecaptcha.reset();

}

grecaptcha.execute();

});

}

 类似资料: