AG
Implementar reCAPTCHA
Ola amigos bom dia estou implementando o reCAPTCHA da google e estou com problemas se alguém puder me dar uma força esta apresentando o seguinte erro segue erro e código:
- <?php
- /**
- * LoginForm
- *
- * @version 1.0
- * @package control
- * @subpackage admin
- * @author Pablo Dall'Oglio
- * @copyright Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
- * @license http://www.adianti.com.br/framework-license
- */
- require 'vendor/google/recaptcha/src/autoload.php';
- use google\recaptcha\src\ReCaptcha\ReCaptcha;
- use google\recaptcha\src\ReCaptcha\RequestMethod;
- use google\recaptcha\src\ReCaptcha\RequestParameters;
- use google\recaptcha\src\ReCaptcha\Response;
- class LoginForm extends TPage
- {
- protected $form; // form
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct($param)
- {
- parent::__construct();
- $ini = AdiantiApplicationConfig::get();
- $this->style = 'clear:both';
- // creates the form
- $this->form = new BootstrapFormBuilder('form_login');
- $this->form->setFormTitle( 'Acesso ao Sistema' );
- // create the form fields
- $login = new TEntry('login');
- $password = new TPassword('password');
- $secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
- $remoteIp = null;
- $gRecaptchaResponse = null;
- $grecaptcha = new \ReCaptcha\ReCaptcha($secret);
- //$resp = $recaptcha->setExpectedHostname('site.com.br')
- // ->verify($gRecaptchaResponse, $remoteIp);
- // define the sizes
- $login->setSize('70%', 40);
- $password->setSize('70%', 40);
- $login->style = 'height:35px; font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
- $password->style = 'height:35px;font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
- $grecaptcha->style = 'height:35px; font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
- $login->placeholder = _t('User');
- $password->placeholder = _t('Password');
- $login->autofocus = 'autofocus';
- $user = '<span style="float:left;margin-left:44px;height:35px;" class="login-avatar"><span class="glyphicon glyphicon-user"></span></span>';
- $locker = '<span style="float:left;margin-left:44px;height:35px;" class="login-avatar"><span class="glyphicon glyphicon-lock"></span></span>';
- $unit = '<span style="float:left;margin-left:44px;height:35px;" class="login-avatar"><span class="fa fa-university"></span></span>';
- $this->form->addFields( [$user, $login] );
- $this->form->addFields( [$locker, $password] );
- $this->form->addFields( ['', $grecaptcha] );
- //$this->form
- if (!empty($ini['general']['multiunit']) and $ini['general']['multiunit'] == '1')
- {
- $unit_id = new TCombo('unit_id');
- $unit_id->setSize('70%');
- $unit_id->style = 'height:35px;font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
- $this->form->addFields( [$unit, $unit_id] );
- $login->setExitAction(new TAction( [$this, 'onExitUser'] ) );
- }
- $btn = $this->form->addAction(_t('Log in'), new TAction(array($this, 'onLogin')), '');
- $btn->class = 'btn btn-primary';
- $btn->style = 'height: 40px;width: 90%;display: block;margin: auto;font-size:17px;';
- $img = new TImage('app/images/adianti.png');
- $img->style = 'text-align:center;';
- $wrapper = new TElement('div');
- $wrapper->style = 'margin:auto; margin-top:100px;max-width:460px;';
- $wrapper->id = 'login-wrapper';
- //$wrapper->add($img);
- $wrapper->add($this->form);
- // add the form to the page
- parent::add($wrapper);
- }
- ?>
Boa tarde Aderson!
Então o problema esta aqui na linha 69:
O metodo addFields adciona um objeto que encapsula a classe TField, a varaiavel $grecaptcha não contem um objeto assim.
O erro é pq o metodo show() não consta em $grecaptcha pois o mesmo não estende TField;
Sujiro vc add direto no form com o metodo add mesmo.
Veja:
Ola boa tarde.
Obrigado pela pronta ajuda. Fiz o que recomendou mas esta apresentando o seguinte erro:
Fatal error: Uncaught Error: Call to undefined method ReCaptchaReCaptcha::show() in C:wampwwwempaylibadiantiwidgetbaseTElement.php on line 343
( ! ) Error: Call to undefined method ReCaptchaReCaptcha::show() in C:wampwwwempaylibadiantiwidgetbaseTElement.php on line 343
Call Stack
# Time Memory Function Location
1 0.3955 390192 {main}( ) ...engine.php:0
2 2.1197 473312 TApplication::run( ) ...engine.php:67
3 2.1683 481720 AdiantiCoreAdiantiCoreApplication::run( ) ...engine.php:35
4 2.3530 598968 LoginForm->show( ) ...AdiantiCoreApplication.php:62
5 2.3530 598968 LoginForm->show( ) ...TPage.php:207
6 2.3531 598968 AdiantiWidgetBaseTElement->show( ) ...TElement.php:343
7 2.3531 598968 AdiantiWrapperBootstrapFormBuilder->show( ) ...TElement.php:343
8 2.3735 610512 AdiantiWidgetBaseTElement->show( ) ...BootstrapFormBuilder.php:724
9 2.3737 610512 AdiantiWidgetFormTForm->show( ) ...TElement.php:343
10 2.3738 610784 AdiantiWidgetBaseTElement->show( ) ...TForm.php:509
Att
Anderson
Consigo fazer isto no form adicionando no código da outra div?
<div class="g-recaptcha form-field" data-sitekey="
Só fazer isso que funciona
A versão 2, a 3 acho que não funciona no Adianti.
Ola Leonardo boa tarde.
Funcionou perfeitamente.
Obrigado pela ajuda