Current path: home/webdevt/cryptoimpot.fr/module/User/src/Form/
?? Go up: /home/webdevt/cryptoimpot.fr/module/User/src
<?php
namespace User\Form;
use Laminas\Form\Form;
use Laminas\InputFilter\InputFilter;
use Application\Form\Element\Recaptcha;
/**
* This form is used to collect user's E-mail address (used to recover password).
*/
class PasswordResetForm extends Form {
const EMAIL = 'email';
const RECAPTCHA = 'g-recaptcha-response';
protected $userRepository;
protected $has_captcha;
/**
* Constructor.
*/
public function __construct(\Doctrine\Common\Persistence\ObjectRepository $userRepository, $has_captcha) {
// Define form name
parent::__construct('password-reset-form');
$this->userRepository = $userRepository;
$this->has_captcha = $has_captcha;
// Set POST method for this form
$this->setAttribute('method', 'post');
$this->addElements();
$this->addInputFilter();
}
/**
* This method adds elements to form (input fields and submit button).
*/
protected function addElements() {
// Add "email" field
$this->add([
'type' => 'email',
'name' => 'email',
'options' => [
'label' => 'Votre email',
],
]);
// Add the CAPTCHA field
// var_dump((bool) imagettfbbox(12, 0, 'arial', 'foo'));
// $this->add([
// 'type' => 'captcha',
// 'name' => 'captcha',
// 'options' => [
// 'label' => 'Human check',
// 'captcha' => [
// 'class' => 'Image',
// 'imgDir' => 'public/img/captcha',
// 'suffix' => '.png',
// 'imgUrl' => '/img/captcha/',
// 'imgAlt' => 'CAPTCHA Image',
// 'font' => './data/font/thorne_shaded.ttf',
// 'fsize' => 24,
// 'width' => 350,
// 'height' => 100,
// 'expiration' => 600,
// 'dotNoiseLevel' => 40,
// 'lineNoiseLevel' => 3
// ],
//// 'captcha' => [
//// 'class' => 'Figlet',
//// 'wordLen' => 6,
//// 'expiration' => 600,
//// ]
// ],
// ]);
// $this->add([
// 'name' => 'g-recaptcha-response',
// 'type' => Recaptcha::class,
// 'options' => [
// 'label' => _( "Please complete the challenge below" ),
// 'no_sitekey' => false,
// 'no_script' => false,
// 'language' => 'en', // see https://developers.google.com/recaptcha/docs/language
// ],
// ]);
// $element = new \Laminas\Captcha\Captcha('g-recaptcha-response');
//$element->setCaptcha(new Application\ReCaptcha(array('private_key' => '6Lei3q0UAAAAAJFCVRcRYGkSY9DAOAfd0DEeEnmu', 'public_key' => '6Lei3q0UAAAAAFKYpVt33JvCvNQnreNYqAgt-IWe', 'theme' => 'dark')));
//$this->add($element);
// Add the CSRF field
$this->add([
'type' => 'csrf',
'name' => 'csrf',
'options' => [
'csrf_options' => [
'timeout' => 600
]
],
]);
// Add the Submit button
$this->add([
'type' => 'submit',
'name' => 'submit',
'attributes' => [
'value' => 'Réinitialisation de mot de passe',
'id' => 'submit',
'class' => 'btn btn-lg btn-primary btn-block'
],
'options' => [
'label' => 'Réinitialiser mon mot de passe'
]
]);
}
/**
* This method creates input filter (used for form filtering/validation).
*/
private function addInputFilter() {
// $inputFilter = new \User\InputFilter\PasswordResetFormInputFilter();
//
// $this->setInputFilter($inputFilter);
if ($this->has_captcha) {
$this->add([
'name' => self::RECAPTCHA,
'required' => true,
'messages' => [_("Please complete the anti-robot check!")],
'validators' => [
['name' => \Application\Form\Validator\RecaptchaValidator::class,],
],
]);
//$this->get( self::RECAPTCHA )->setBreakOnFailure( true );
}
// Create main input filter
$inputFilter = $this->getInputFilter();
// Add input for "email" field
$inputFilter->add([
'name' => 'email',
'required' => true,
'filters' => [
['name' => 'StringTrim'],
],
'error_message' => 'Veuillez indiquer une adresse email valide',
'validators' => [
[
'name' => 'EmailAddress',
'options' => [
'allow' => \Laminas\Validator\Hostname::ALLOW_DNS,
'useMxCheck' => false,
],
],
[
'name' => 'NotEmpty',
'options' => [
'messages' => array(
\Laminas\Validator\NotEmpty::IS_EMPTY => 'Veuillez indiquer votre email',
),
],
],
],
]);
}
}