hi there, I have a problem using ZendService\ReCaptcha\ReCaptcha
in my Contact form. I already registered in https://www.google.com/recaptcha/admin.
I also installed ZendService\ReCaptcha\ReCaptcha
from https://github.com/zendframework/ZendService_ReCaptcha and here is my composer.json code:
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for Zend Framework zend-mvc applications",
"type": "project",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"mvc",
"zf"
],
"homepage": "http://framework.zend.com/",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^5.6 || ^7.0",
"zendframework/zend-component-installer": "^1.0 || ^0.7 || ^1.0.0-dev@dev",
"zendframework/zend-mvc": "^3.0.1",
"zfcampus/zf-development-mode": "^3.0",
"zendframework/zend-db": "^2.8.1",
"zendframework/zend-mvc-form": "^1.0",
"zendframework/zend-json": "^3.1",
"zendframework/zend-session": "^2.7.1",
"zendframework/zend-navigation": "^2.8",
"zendframework/zend-paginator": "^2.7",
"zendframework/zend-permissions-acl": "^2.6",
"tasmaniski/zend-layout-change": "^1.0",
"zendframework/zend-captcha": "^2.7",
"zendframework/zendservice-recaptcha": "*",
"zendframework/zend-http": "^2.5.4"
},
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/",
"Blog\\": "module/Blog/src/",
"PageBuilder\\": "module/PageBuilder/src",
"Contact\\": "module/Contact/src",
"ZendService\\ReCaptcha\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"ApplicationTest\\": "module/Application/test/"
}
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev",
"dev-develop": "3.1-dev"
}
}
,"repositories": [
{
"type": "composer",
"url": "https://packages.zendframework.com/"
}
]
,
"scripts": {
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"development-disable": "zf-development-mode disable",
"development-enable": "zf-development-mode enable",
"development-status": "zf-development-mode status",
"post-create-project-cmd": [
"@development-enable"
],
"serve": "php -S 0.0.0.0:8080 -t public public/index.php",
"test": "phpunit"
}
}
here is my Contact\Controller\IndexController
for using re-captcha:
public function indexAction()
{
$recaptcha = new \ZendService\ReCaptcha\ReCaptcha(
'PUB_KEY',
'PRIVATE_KEY');
return new ViewModel
([
'recaptcha'=>$recaptcha,
]);
}
and here the index.phtml code:
echo $this->recaptcha->getHTML();
if(isset($_POST['recaptcha_response_field'])){
$recaptcha_challenge =$_POST['recaptcha_challenge_field'];
$recaptcha_response = $_POST['recaptcha_response_field'];
if(isset($recaptcha_challenge)&&
isset($recaptcha_response) ||
!empty($recaptcha_challenge)&&
!empty($recaptcha_response)){
$result = $this->recaptcha->verify(
$recaptcha_challenge,
$recaptcha_response
);
if (!$result->isValid())
{
echo $result->getErrorCodes();
}
}
}
but after all my form is submitted without filling re-captcha part. and there is no error. what should I do?