Search code examples
validationsymfonyfosuserbundlefosrestbundle

How to validate a POST request for postUserAction


I get a problem with the validation of a new user request on my api. I know there's a problem in my code but I cannot figure it out :

UserType

postUserAction

And I send via google Postman, this json :

{
  "username":"Username",
  "email":"example@mail.com",
  "plainPassword":"SecretPassword",
  "lastname":"Smith",
  "firstname":"John",
  "job_position":"CEO",
  "phone":"+666133742",
  "company_name":"Microtosh",
  "website":"www.omgthatsaflippingspider.com",
  "sector":"Food & Stuff",
  "address":"12 st Overkill",
  "city":"SinCity",
  "zip_code":"W4224",
  "country":"US",
  "billing_infos_same_as_company":true,
  "putf":"1",
  "das":"Manchester United"
}

Now I seems to validate but I get an error :

Column 'password' cannot be null

When I look up the $form -- before $userManager->updateUser($user) -- I get this :

plainPassword:
{
    -children:
    {
        -first:
        {
            -errors:
            [
                "fos_user.password.mismatch"
            ]
        }
        second: [ ]
    }
}

Now first, why does it validate since it didn't find a match between password and confirmation ?

And am I doing the right thing, with the creation of a new user ? I don't understand what I am missing.


Solution

  • Just change the form type of password field to password instead of repeated and it should work ;)