dev-master
9999999-devSymfony form type extension which substitutes non-string data with default value for requested form types.
MIT
The Requires
- php >=5.3.3
- symfony/form ~2.4
- telesto/symfony-form-utils *@dev
by Paweł Ulewicz
form symfony forms
Wallogit.com
2017 © Pedro Peláez
Symfony form type extension which substitutes non-string data with default value for requested form types.
Symfony form type extension which substitutes non-string data with default value for requested form types., (*1)
Problem:, (*2)
Symfony framework by default does not protect your application from type errors in your forms., (*3)
If someone adds '[]' to form input name (using firebug, opera dragonfly or similar tool), the data sent to your application will be an array instead of string and (most likely) some validator will throw Symfony\Component\Validator\Exception\UnexpectedTypeException, which (if uncaught) will result in 500 Internal server error http response and 'Uncaught PHP Exception' entry log., (*4)
Example:, (*5)
name="form_name[fieldName]" (normal input name) name="form_name[fieldName][]" (modified input name)
But you probably don't want that error in your logs, and you don't want your application to send 5xx response, because it is not (semantically) a server error., (*6)
Possible solutions:, (*7)
$form->submit() to catch UnexpectedTypeException (which is dirty).This project provides solution number 3., (*8)
Usage:, (*9)
services:
form.type_extention.ensure_string:
class: Telesto\VendorExt\Symfony\Form\EnsureString\Type\FormTypeEnsureStringExtension
arguments:
- ['text', 'integer', 'hidden', 'number', 'percent', 'money'] # add non-standard types if you use them
tags:
- { name: form.type_extension, alias: form }
License: MIT, (*10)
Symfony form type extension which substitutes non-string data with default value for requested form types.
MIT
form symfony forms