Edición de «Ejemplo de reCAPTCHA en KumbiaPHP v2»
De KumbiaPHP Framework Wiki
Advertencia: no has iniciado sesión. Tu dirección IP se hará pública si haces cualquier edición. Si inicias sesión o creas una cuenta, tus ediciones se atribuirán a tu nombre de usuario, además de otros beneficios.
Puedes deshacer la edición. Antes de deshacer la edición, comprueba la siguiente comparación para verificar que realmente es lo que quieres hacer, y entonces guarda los cambios para así efectuar la reversión.
Revisión actual | Tu texto | ||
Línea 37: | Línea 37: | ||
*/ | */ | ||
private static $_privateKey = 'TU_CLAVE_PRIVADA'; | private static $_privateKey = 'TU_CLAVE_PRIVADA'; | ||
− | |||
− | |||
− | |||
− | |||
/** | /** | ||
* Genera el HTML con el código reCaptcha | * Genera el HTML con el código reCaptcha | ||
* | * | ||
+ | * @param $error | ||
* @return string | * @return string | ||
*/ | */ | ||
− | public static function html() | + | public static function html($error = NULL) |
{ | { | ||
− | return recaptcha_get_html(self::$_publicKey, | + | return recaptcha_get_html(self::$_publicKey, $error); |
} | } | ||
/** | /** | ||
* Valida que el código colocado sea el correcto | * Valida que el código colocado sea el correcto | ||
− | * @return | + | * @return Response |
*/ | */ | ||
− | public static function | + | public static function validate() |
{ | { | ||
$ret = recaptcha_check_answer (self::$_privateKey, | $ret = recaptcha_check_answer (self::$_privateKey, | ||
Línea 61: | Línea 58: | ||
$_POST['recaptcha_challenge_field'], | $_POST['recaptcha_challenge_field'], | ||
$_POST['recaptcha_response_field']); | $_POST['recaptcha_response_field']); | ||
− | + | ||
− | + | return $ret; | |
− | |||
− | |||
− | |||
− | |||
} | } | ||
} | } | ||
Línea 87: | Línea 80: | ||
{ | { | ||
// Realizamos la comprobacion | // Realizamos la comprobacion | ||
− | + | $ret = reCaptcha::validate(); | |
+ | if ($ret->is_valid) { | ||
$this->Datos = Input::post('Datos'); | $this->Datos = Input::post('Datos'); | ||
View::select("validado"); | View::select("validado"); | ||
} | } | ||
+ | // Enviamos el error a la vista | ||
+ | $this->previousError = $ret->error; | ||
+ | }else{ | ||
+ | //si no se ha enviando el captcha declaramas la variable a NULL | ||
+ | $this->previousError = NULL; | ||
} | } | ||
} | } | ||
Línea 104: | Línea 103: | ||
echo Form::text('Datos.nombre'); | echo Form::text('Datos.nombre'); | ||
− | echo reCaptcha::html(); | + | echo reCaptcha::html($previousError); |
echo Form::submit('Enviar datos'); | echo Form::submit('Enviar datos'); |