2017 © Pedro Peláez
 

library symfony-form-ensure-string

Symfony form type extension which substitutes non-string data with default value for requested form types.

image

telesto/symfony-form-ensure-string

Symfony form type extension which substitutes non-string data with default value for requested form types.

  • Wednesday, May 14, 2014
  • by mdopt
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

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)

  1. Use try-catch block for every $form->submit() to catch UnexpectedTypeException (which is dirty).
  2. Wrap your form in another form that does exception catching for you and returns appropriate error. You could use a custom form factory to do that automatically.
  3. Use form type extension that fixes non-string values.

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)

The Versions

14/05 2014

dev-master

9999999-dev

Symfony form type extension which substitutes non-string data with default value for requested form types.

  Sources   Download

MIT

The Requires

 

by Paweł Ulewicz

form symfony forms