php - Validation based on another field -
I am new to this but turns either the sections used are removed or any unit is required. The implementation of the two fields is as follows, I have applied a verification using a set of conditions within the controller Edit User Modify your class as follows Of course you have to be able to enter all the notifications in the When you use Symfony framework and a dead ended during implementation. I'll have to validate the
new password and
password confirmation field only if the user's
current password is entered.
// If this field is loaded $ builder-gt; ('Current password', 'password', array ('label' = & gt; 'current password', 'expected' = & gt; false, 'attr' = & gt; array ('class' => Form-control "error," '=' '))); // This must be filled in fields or set as the required $ builder- & gt; Add ('password', 'duplicated', array ('type' = & gt; 'password', 'required' = & gt; wrong, invalid_message = '> error message: PASSWORDS_DO_NOT_MATCH,' options' => ; Array ('atri' => array ('class' = & gt;' password-field form-control ')),' first_ option '=> array (' label '= & gt; wrong;' Error_bubbling '= & gt; true,' label_attr '= & gt; array (' class' = & gt; 'col-sm-4-control-label')), 'seconds_points' = & gt; array (' label ' = & Gt; wrong, 'label_attr' = & gt; array ('square' = & gt; 'col-sm-4-control-label')));
if but it would be best to learn the correct way to run assumptions for the scenario such as this .
entity
& Lt ;? Php namespace prose bundle \ AccountsBundle \ Entity; As the Symfony \ Component \ Validator \ Constraints use; Use Symfony \ Component \ Security \ Core \ User \ UserInterface; Use the bundle \ accountsBundle \ Custom \ ErrorMessages; Class user user interface, \ serializable {/ ** * @Assert \ email (message = error message: EMAIL_ADDRESS_INVALID) applies * @Assert \ NotBlank (message = error message: EMAIL_ADDRESS_EMPTY) * / private $ email; / ** * @Assert \ NotBlank (Message = Error Message: PASSWORD_EMPTY, Group = {"Full"}) * / Private $ Password; Private $ old password; Private $ ID; Private $ userId; Private $ name; Private $ username; Public function __ composition () {} function set email ($ email) {$ this- & gt; Email = $ email; $ This- & gt; User name = $ email; } GetEmail () function {return $ this-> E-mail; } Function Set Password ($ password) {$ this- & gt; Password = $ password; } GetPassword function () {return $ this-> password; } Function Set Old Password ($ old password) {$ this- & gt; Old password = $ old password; } GetOldPassword function () {return $ this- & gt; Old Password; } Function setId ($ id) {$ this- & gt; Id = $ id; } Function getId () {return $ this- & gt; Id; } Function Set User ID ($ user-) {$ this- & gt; UserId = $ userId; } GetUserId () function {return $ this- & gt; UserId; } Function Set Name (name name $ name) {$ this- & gt; Name = $ name; } GetName function () {return $ this-> Name; } Delete public functionsCredential () {} public function getRoles () {return array ('ROLE_USER'); } Public function getSalt () {} Public Function getUsername () {Return $ this- & gt; User name; }}
Use Symfony \ Component \ Validator \ Constraints as; Use Symfony \ Component \ Validator \ ExecutionContext; / ** * @@Asset callback (methods = {"verify password"}) / Class user user interface, \ serializable {// all your old code here Public Verify Password (Execution Contex $ $ Reference) {/ In case of your control failure about / password, you can add that snippet of field // $ code-> addViolationAtPath ($ propertyPath, 'your message here', array (), null); }}
passwordVerify function and the fastest way to do this is to create the field
verifyPassword in your unit, so when you form the form with the unit, all the data will be there.
isValid () , this snippet of code will automatically call the callback method
Comments
Post a Comment