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

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework 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