rest - Symfony2 form submit invalid boolean value -
i have strange problem symfony (v 2.3.2) form. it's simple form without relations. should noted form used in rest api only.
so have published field (boolean). on entity it's set false default.
on update, rest api client sends put request correct aka ...&[entity]published=0&...
. value shown in symfony profiler in form parameters.
however i've noticed actual value in database set true (or 1 it's tinyint).
so, find out what's problem, added throw statement after $form->submit($request);
throw new \exception(sprintf('request: %s, form: %s', $request->get('entity')['published'], $form->get('published')->getdata()));
or
throw new \exception(sprintf('request: %s, form: %s', $request->get('entity')['published'], $form->getdata()->getpublished()));
the exception message says: request: 0, form: 1
. means somewhere in submit method string value '0' converted 1.
the field constructed $builder->add('published', 'checkbox', [ 'required' => false ])
also i've noticed strange thing, may related. on symfony profiler, panel request, i'm getting error: warning: json_encode(): invalid utf-8 sequence in classes.php line 3758
, i'm not sending strange characters - word "test".
you shouldn't use checkbox form type in api, 0 doesn't mean false.
you should implement new boolean form type transform 1, '1' , true true, , else false (for example).
here example: https://gist.github.com/fsevestre/abfefe0b66e5f5b24c60
Comments
Post a Comment