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\Form\Fieldset;
use Laminas\InputFilter\InputFilter;
/**
* This form is used to collect user's login, password and 'Remember Me' flag.
*/
class LoginForm extends Form {
/**
* Constructor.
*/
public function __construct() {
// Define form name
parent::__construct('login-form');
// 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' => 'text',
'name' => 'email',
'options' => [
'label' => 'Your E-mail',
],
]);
// Add "password" field
$this->add([
'type' => 'password',
'name' => 'password',
'options' => [
'label' => 'Password',
],
]);
// Add "remember_me" field
$this->add([
'type' => 'checkbox',
'name' => 'remember_me',
'options' => [
'label' => 'Remember me',
],
]);
// Add "redirect_url" field
$this->add([
'type' => 'hidden',
'name' => 'redirect_url'
]);
// 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' => 'Sign in',
'id' => 'submit',
'class' => 'btn btn-lg btn-primary btn-block'
],
'options' => [
'label' => 'Se connecter'
]
]);
}
/**
* This method creates input filter (used for form filtering/validation).
*/
private function addInputFilter() {
// Create main input filter
$inputFilter = $this->getInputFilter();
// Add input for "email" field
$inputFilter->add([
'name' => 'email',
'required' => true,
'filters' => [
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => 'EmailAddress',
'options' => [
'allow' => \Laminas\Validator\Hostname::ALLOW_DNS,
'useMxCheck' => false,
],
],
],
]);
// Add input for "password" field
$inputFilter->add([
'name' => 'password',
'required' => true,
'filters' => [
],
'validators' => [
[
'name' => 'StringLength',
'options' => [
'min' => 6,
'max' => 50,
'messages' => array(
\Laminas\Validator\StringLength::INVALID => 'Le mot de passe doit comporter entre 6 et 50 caractères',
\Laminas\Validator\StringLength::TOO_SHORT => 'Le mot de passe doit comporter au moins 6 caractères',
\Laminas\Validator\StringLength::TOO_LONG => 'Le mot de passe doit comporter au maximum 50 caractères',
),
],
],
],
]);
// Add input for "remember_me" field
$inputFilter->add([
'name' => 'remember_me',
'required' => false,
'filters' => [
],
'validators' => [
[
'name' => 'InArray',
'options' => [
'haystack' => [0, 1],
]
],
],
]);
// Add input for "redirect_url" field
$inputFilter->add([
'name' => 'redirect_url',
'required' => false,
'filters' => [
['name' => 'StringTrim']
],
'validators' => [
[
'name' => 'StringLength',
'options' => [
'min' => 0,
'max' => 2048
]
],
],
]);
}
}