我在网络开发方面的经验几乎为零,但我找到了一个与reCAPTCHA联系的simple example,并试图弄清楚如何让它在我的WordPress网站上运行。有live demo。
是否有可能在index.js中实现'submit'函数,它检查验证码,异步发送表单数据并处理响应?
new Vue({
// root node
el: "#app",
// the instance state
//...
methods: {
// submit form handler
submit: function() {
this.submitted = true;
},
//..
});
如果是,服务器端可以有一个处理请求的PHP脚本,调用mail(...)并返回“OK”,但是在这种情况下如何检查验证码并不清楚?谁检查它,JavaScript或PHP?
这是我使用的类方法。参数($ gRecaptchaResponse)是谷歌使用javascript提交验证码时返回的内容
protected function validateGoogleRecaptcha($gRecaptchaResponse)
{
$secretKey = $this->config['application']['captcha']['recaptcha']['secretKey'];
$reCaptcha = new \ReCaptcha($secretKey);
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$gRecaptchaResponse
);
return $response;
}