Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/07/2017, 02:05
Avatar de gogupe
gogupe
 
Fecha de Ingreso: octubre-2006
Ubicación: Mallorca
Mensajes: 897
Antigüedad: 17 años, 6 meses
Puntos: 32
Validacion dos captcha recapcha en php

Hola a todos.

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>

__________________
Somos una serie de acontecimiento que puede venir al caso en un momento dado.

Última edición por gogupe; 27/07/2017 a las 03:21