ZF2 check - a field is required if another element is not empty

I had experience creating custom validation in Zend Framework 2 (using version 2.0.5 currently). I am interested in creating a password section for changing the "edit profile" form. What I want to have has 3 fields:

  • Current Password,
  • New Password,
  • Confirm the new password.

Then I want to check the following:

  • If a new password is set, the current password must also be set (and authenticated), and the new password must match the new password.
  • If the current password is set, you must also enter a new password and confirm the new password.
  • If none of them are installed, enable editing the rest of the profile to continue checking.

I think that you can get the gist of what I need, I’m looking for a reusable way to do this using Zend Framework 2. Ideally, creating a special validator so that forms can be reused, it was believed that I suspect a factory might be better . Nothing, so I don’t need to check it at the controller / service level and repeat myself wherever I want to use this.

Respectfully,

ISE

+6
source share
1 answer

You can add a custom filter, but I think that this could also be done using verification groups and separately checking input groups.

you can add password fields to a separate group and only confirm this group if the main password is not empty.

http://framework.zend.com/manual/2.0/en/modules/zend.input-filter.intro.html

http://framework.zend.com/manual/2.0/en/modules/zend.form.collections.html#validation-groups-for-fieldsets-and-collection

-1
source

All Articles