ibrows/IbrowsFriendlyFormBundle

Name: IbrowsFriendlyFormBundle

Owner: PwC Experience Center

Description: Renames form fields for rendering and converts back for submitting data

Created: 2015-07-08 07:10:05.0

Updated: 2015-07-08 07:10:46.0

Pushed: 2015-07-08 07:14:22.0

Homepage: null

Size: 116

Language: PHP

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

IbrowsFriendlyFormBundle

Renames with an FormExtension on “finishView” the form-fields to a configured new name.

For example

://localhost:8000/de/product/filter?productfilter%5Bcategories%5D%5B%5D=472&productfilter%5Bcategories%5D%5B%5D=462&productfilter%5Bprice%5D%5Bfirst%5D=0&productfilter%5Bprice%5D%5Bsecond%5D=250&productfilter%5Byear%5D%5Bfirst%5D=1985&productfilter%5Byear%5D%5Bsecond%5D=2015&productfilter%5Borganics%5D=&productfilter%5BfastSearch%5D=

Will be

://localhost:8000/de/product/filter?cat%5B%5D=472&cat%5B%5D=462&pricefrom=0&priceto=250&yearfrom=1985&yearto=2015&organics=&q=
Configuration
FormType
/**
 * @param OptionsResolverInterface $resolver
 */
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
    parent::setDefaultOptions($resolver);
    $resolver->setDefaults(
        array(
            'friendly' => array(
                'productfilter[categories]*'   => 'cat',
                'productfilter[price][first]'  => 'pricefrom',
                'productfilter[price][second]' => 'priceto',
                'productfilter[year][first]'   => 'yearfrom',
                'productfilter[year][second]'  => 'yearto',
                'productfilter[organics]'      => 'organics',
                'productfilter[fastSearch]'    => 'q'
            )
        )
    );
}
Handle Request
$productFilterForm = $this->createForm(new ProductSearchType());

$productFilterForm->handleRequest($request); //Do not use handlRequest or submit on your own now!
$this->get('ibrows.friendly_form_extension')->submit($productFilterForm, $request); //Use this service to bind correct transformed data

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.