I've added validation to a form and found that in some cases it is losing the invalid data I am feeding it and saving 0s instead. The output at the bottom shows that if I post the latitude as 'zzzzzz' (clearly not a number nor between -90 and 90) the form is declared as valid and saved with the value 0 How can that happen given that I have declared the input must be a number?
ProxyType.php buildForm()
$builder
->add('siteName', null, array('label' => 'Site name'))
....
->add('latitude', 'number', array('label' => 'Latitude'))
->add('longitude', 'number', array('label' => 'Longitude'))
....
;
ProxyController.php createAction
....
$postData = $request->request->get('niwa_pictbundle_proxytype');
$this->get('logger')->info('Posted latitude = '.$postData['latitude']);
$form = $this->createForm(new ProxyType(), $entity);
$form->bindRequest($request);
if ($form->isValid()) {
$this->get('logger')->info('Form declared valid : latlong ('.$entity->getLatitude().','.$entity->getLongitude().')');
....
validation.yml
Acme\PictBundle\Entity\Proxy:
properties:
longitude:
- Min: { limit: -180 }
- Max: { limit: 180 }
latitude:
- Max: { limit: 90 }
- Min: { limit: -90 }
Output
[2012-09-28 02:05:30] app.INFO: Posted latitude = zzzzzz [] []
[2012-09-28 02:05:30] app.INFO: Form declared valid : latlong (0,0) [] []