The form is never valid, but $form->getErrors()
gives no error.
Since its gonna be a REST API test it with DEV HTTP client
test data is
Header:
Content-Type:application/json
Body:
{"username":"sad","password":"123","email":"[email protected]"}
I don't have any validation.yml file
Is there any any method to find out whats going wrong (error Message)?
public function postUserAction(Request $request)
{
return $this->processForm(new User(),$request);
}
private function processForm(User $user, Request $request )
{
$form = $this->createForm(new UserType(), $user);
$form->handleRequest($request);
if ($form->isValid()) {
return array('form' => 'valid');
}
return \FOS\RestBundle\View\View::create($form->getErrors(),400);
}
After a little debug: isValid() checks form several things eg if the form has been submitted. It wasnt, so i changed to
...
$form = $this->createForm(new UserType(), $user);
//$form->handleRequest($request);
$form->submit($request);
if ($form->isValid()) {
...
now its valid.
When debugging a form validation,
use $form->getErrorsAsString()
instead of $form->getErrors()
.
(which will run in to deep level including the form children.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With