symfony/symfony — Issue #2924: Unwanted casting of numeric types allows incorrect pass of validation for AJAX posts
Author: PorridgeBear
Created: 2011-12-19 17:50:11+00:00
State: open

I have some properties of a deeply nested entity that need to be decimal. I have them marked up that way via the ORM Doctrine column type. Symfony2 renders an input field with a pattern attribute.

I am validating via AJAX. I post over the data, use the form bindRequest to setup an instance of the entity but then use the validator service.

The thing I am finding is that if my user enters some letters 'abc' into a decimal-mapped column property, the bindRequest is setting the property to 0 (zero) rather than 'abc' so that the Type(float) constraint is always calling is_float(0) unless I specify an actual number in the field.

Because I am using AJAX, the field validates behind the scenes due to this setting of 0 rather than 'abc' but my UI stays the same. as Symfony is not called again to regenerate it like you would have if I were posting the whole page.

2 options really - figure out a way of returning the modified value back to my UI in the AJAX response to reset it, or be able to tell Symfony to validate the value before setting/casting the values on my entity so that it truly validates the input and not the post-casted values.

I think actually the latter is what should truly be happening. I think Symfony should not be helping me out by casting values here.