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 register user.
*/
class RegisterForm extends Form {
/**
* Constructor.
*/
public function __construct() {
// Define form name
parent::__construct('register-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',
],
]);
$this->add([
'type' => 'password',
'name' => 'password-verify',
'options' => [
'label' => 'Password',
],
]);
// 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' => 6000
]
],
]);
// Add the Submit button
$this->add([
'type' => 'submit',
'name' => 'submit',
'attributes' => [
'value' => 'Sign in',
'id' => 'submit',
],
]);
}
/**
* 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'],
],
'error_message' => 'Veuillez indiquer une adresse email valide',
'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',
),
],
],
],
]);
$inputFilter->add([
'name' => 'password-verify',
'required' => true,
'filters' => [
],
'validators' => [
[
'name' => 'Identical',
'options' => [
'token' => 'password',
'messages' => array(
\Laminas\Validator\Identical::NOT_SAME => 'Le mot de passe doit être identique dans les 2 champs'
),
],
],
],
]);
// Add input for "redirect_url" field
$inputFilter->add([
'name' => 'redirect_url',
'required' => false,
'filters' => [
['name' => 'StringTrim']
],
'validators' => [
[
'name' => 'StringLength',
'options' => [
'min' => 0,
'max' => 2048
]
],
],
]);
}
}