How to check the registration form in zend framework 2?

I am trying to verify the user registration form in Zend Framework 2.

More specifically, how to check email, ZF1 I could do:

$email->setValidators( array(new Zend_Validate_EmailAddress()) ); 

I wonder if I can just call something like that.

I am also wondering how to check two fields, which should be the same as password field and password verification.

I assume that when I say if($form->isValid()).. this will check the getInputFilter() method for the whole check.

I am watching ZfcUser , but now I can’t understand, because I don’t understand completely understand how ZF2 works.

Any ideas, maybe a simple example?

thanks

+4
source share
2 answers

Have you read the official official tutorial to find out how the new ZF2 Form component works?

At a very high level, you need a Form object and a Filter object working together. The Filter object is where you place filters and validators. However, if you use a form element of type EmailAddress in Form , it will automatically add the correct validator. The manual has additional information .

I recently did a web form seminar for Zend, which you can find on this page .

+8
source

I get it.

validators are multidimensional arrays, and each array has a name and some parameters. It may be a bit related at the beginning to notice this, but the big configuration in zf2 is this way

see example for password:

 $inputFilter->add($factory->createInput([ 'name' => 'password', 'required' => true, 'filters' => [ ['name' => 'StringTrim'], ], 'validators' => [ [ 'name' => 'StringLength', 'options' => [ 'encoding' => 'UTF-8', 'min' => 6, 'max' => 128, ], ], ], ])); $inputFilter->add($factory->createInput([ 'name' => 'password_verify', 'required' => true, 'filters' => [ ['name' => 'StringTrim'], ], 'validators' => [ array( 'name' => 'StringLength', 'options' => array( 'min' => 6 ), ), array( 'name' => 'identical', 'options' => array('token' => 'password' ) ), ], ])); 

Note that in php 5.3> an array can be written as array() or [] , in the above example I mix them for no particular reason.

+1
source

Source: https://habr.com/ru/post/1439077/


All Articles