Lançado Adianti Framework 7.6!
Clique aqui para saber mais
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: ...
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:

  1. <?php
  2. /**
  3.  * LoginForm
  4.  *
  5.  * @version    1.0
  6.  * @package    control
  7.  * @subpackage admin
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12.  
  13. require 'vendor/google/recaptcha/src/autoload.php';
  14. use google\recaptcha\src\ReCaptcha\ReCaptcha
  15. use google\recaptcha\src\ReCaptcha\RequestMethod;
  16. use google\recaptcha\src\ReCaptcha\RequestParameters;
  17. use google\recaptcha\src\ReCaptcha\Response;
  18.  
  19. class LoginForm extends TPage
  20. {
  21.     protected $form// form
  22.     
  23.     /**
  24.      * Class constructor
  25.      * Creates the page and the registration form
  26.      */
  27.     function __construct($param)
  28.     {
  29.         parent::__construct();
  30.         
  31.         $ini  AdiantiApplicationConfig::get();
  32.         
  33.         $this->style 'clear:both';
  34.         // creates the form
  35.         $this->form = new BootstrapFormBuilder('form_login');
  36.         $this->form->setFormTitle'Acesso ao Sistema' );
  37.         
  38.         
  39.         // create the form fields
  40.         $login = new TEntry('login');
  41.         $password = new TPassword('password');
  42.         $secret "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
  43.         $remoteIp null;
  44.         $gRecaptchaResponse null;
  45.         $grecaptcha = new \ReCaptcha\ReCaptcha($secret);
  46.         //$resp = $recaptcha->setExpectedHostname('site.com.br')
  47.         //                  ->verify($gRecaptchaResponse, $remoteIp);  
  48.         // define the sizes
  49.         $login->setSize('70%'40);
  50.         $password->setSize('70%'40);
  51.         $login->style 'height:35px; font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
  52.         $password->style 'height:35px;font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
  53.         
  54.         $grecaptcha->style 'height:35px; font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
  55.         
  56.         $login->placeholder _t('User');
  57.         $password->placeholder _t('Password');
  58.         
  59.         $login->autofocus 'autofocus';
  60.         $user '<span style="float:left;margin-left:44px;height:35px;" class="login-avatar"><span class="glyphicon glyphicon-user"></span></span>';
  61.         $locker '<span style="float:left;margin-left:44px;height:35px;" class="login-avatar"><span class="glyphicon glyphicon-lock"></span></span>';
  62.         $unit '<span style="float:left;margin-left:44px;height:35px;" class="login-avatar"><span class="fa fa-university"></span></span>';
  63.         
  64.         $this->form->addFields( [$user$login] );
  65.         $this->form->addFields( [$locker$password] );
  66.         $this->form->addFields( [''$grecaptcha] );
  67.         
  68.         //$this->form
  69.         
  70.         if (!empty($ini['general']['multiunit']) and $ini['general']['multiunit'] == '1')
  71.         {
  72.             $unit_id = new TCombo('unit_id');
  73.             $unit_id->setSize('70%');
  74.             $unit_id->style 'height:35px;font-size:14px;float:left;border-bottom-left-radius: 0;border-top-left-radius: 0;';
  75.             $this->form->addFields( [$unit$unit_id] );
  76.             $login->setExitAction(new TAction( [$this'onExitUser'] ) );
  77.         }
  78.         
  79.         $btn $this->form->addAction(_t('Log in'), new TAction(array($this'onLogin')), '');
  80.         $btn->class 'btn btn-primary';
  81.         $btn->style 'height: 40px;width: 90%;display: block;margin: auto;font-size:17px;';
  82.         
  83.         $img = new TImage('app/images/adianti.png');
  84.         $img->style 'text-align:center;';
  85.                         
  86.         $wrapper = new TElement('div');
  87.         $wrapper->style 'margin:auto; margin-top:100px;max-width:460px;';
  88.         $wrapper->id    'login-wrapper';
  89.         //$wrapper->add($img);
  90.         $wrapper->add($this->form);
  91.         
  92.         // add the form to the page
  93.         parent::add($wrapper);
  94.     }
  95. ?>

Curso completo Meu Negócio Pronto
Use para si, ou transforme em um negócio: Inclui aulas e códigos-fontes
Gestor de conteúdo (SITE) + Loja Virtual (E-Commerce) + Emissor de Notas para infoprodutos


Meu negócio pronto Quero me inscrever agora!

Comentários (7)


JD

Boa tarde Aderson!
Então o problema esta aqui na linha 69:
  1. <?php
  2. $this->form->addFields( [''$grecaptcha] );
  3. ?>

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:
  1. <?php
  2. $this->form->add($grecaptcha);
  3. ?>
AG

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
AG

Consigo fazer isto no form adicionando no código da outra div?

<div class="g-recaptcha form-field" data-sitekey="
  1. <?php echo $siteKey?>
"></div>
AG

<div class="g-recaptcha form-field" data-sitekey="
  1. <?php echo $siteKey?>
"></div>
LG

Só fazer isso que funciona
  1. <?php
  2.             include_once 'app/lib/recaptcha/ReCaptcha.php';
  3.             $use "<script src='https://www.google.com/recaptcha/api.js?hl=pt-BR'></script>";
  4.             $captcha =  '<div class="g-recaptcha" data-sitekey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></div>';
  5.             $row $this->form->addFields([$use$captcha]);
  6.             $row->layout = ['col-sm-3, col-sm-3'];
  7. ?>
LG

A versão 2, a 3 acho que não funciona no Adianti.
AG

Ola Leonardo boa tarde.

Funcionou perfeitamente.

Obrigado pela ajuda