Tengo el siguiente código, lo que quiero hacer es como validar dos captcha que hay en una misma página.
Solo me valida el primero, pero es que no se como se hace para diferencia el uno del otro cuando hace submit.
Gracias
Código PHP:
<?php
include ($_SERVER['DOCUMENT_ROOT']."/function/captcha/recaptchalib.php");
if ($_POST['sb_submit1']!="")
{
$secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$response = null;
$reCaptcha = new ReCaptcha($secret);
if ($_POST["g-recaptcha-response"])
{
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]);
}
if ($response != null && $response->success)
{
//Ok
//Resto del proceso submit
}
else
{
$mensaje_error="Por favor active el código de seguridad.";
}
}
if ($_POST['sb_submit2']!="")
{
$secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$response = null;
$reCaptcha = new ReCaptcha($secret);
if ($_POST["g-recaptcha-response"])
{
$response = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["g-recaptcha-response"]);
}
if ($response != null && $response->success)
{
//Ok
//Resto del proceso submit
}
else
{
$mensaje_error="Por favor active el código de seguridad.";
}
}
?>
Código HTML:
<!DOCTYPE html> <html lang="es"> <head> <meta charset="UTF-8"> <title></title> <meta name="description" content=""> <meta name="keywords" content=""> <script src="https://www.google.com/recaptcha/api.js?onload=CaptchaCallback&render=explicit&hl=es" async defer></script> <script type="text/javascript"> var CaptchaCallback = function() { grecaptcha.render('RecaptchaField1', {'sitekey' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}); grecaptcha.render('RecaptchaField2', {'sitekey' : 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'}); }; </script> </head> <body> <div id="main"> <form method="post" name="form_1"> <p><input type="text" name="nombre1" required/></p> <p><div id="RecaptchaField1"></div></p> <p"><input type="submit" name="sb_submit1" value="Enviar1 " /></p> </form> <form method="post" name="form_2"> <p><input type="text" name="nombre2" required/></p> <p><div id="RecaptchaField2"></div></p> <p"><input type="submit" name="sb_submit2" value="Enviar 2" /></p> </form> </html>