Validation with symfony2 form and model

I have a model that has a field token

and a field of type choice

"userType". This single form can be used to register a user in two ways:

  • Email and Password - Token Usage
  • Using Fb or G + - must pass token

I'm in a dilemma where and how to check the marker check. In my opinion I have two approaches as described below:

Approach 1:

Add token field in Type Type Class as optional field and write Custom Validation to check if userType field value is "Fb" or "G +", check the token and throw an exception.

Approach 2:

Write the event subscriber and check if the user type select field is "FB" or "G +", then only dynamically add the token field as a required field. In this case, I think I need to remove the token from my model (need to offer a suggestion as well).

Please help me on this, any other suggestions or approaches are also welcome.

+3


source to share





All Articles