0

I'm trying to create/edit users and I'm having a slight problem with the password field.

When creating a user, it is fair to assume that the password field is required, however, I don't want it required when editing a user

Is there an easy way to do this?

I'm using the SonataAdminBundle to manage the User Form (NOT SonataUserBundle)

user1970557
  • 515
  • 1
  • 9
  • 23

1 Answers1

0

I think you can do it in two ways:

  1. Use inheritance. Create a base FormType and then inherit it to create CreateUserType and EditUserType that add custom password settings
  2. Use same form and leave password as not required, then in the "create user" controller check if password field has been filled and throw an exception if it is empty

Maybe there are more approaches to your problem. I usually use the second one but choose the one fits best to you.

Gorka Lauzirika
  • 303
  • 5
  • 18