ibrows/friendly-form-bundle

Renames form fields for rendering and converts back for submitting data

3.0.0 2015-07-08 07:12 UTC

README

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

For example

http://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

http://localhost:8000/de/product/filter?cat%5B%5D=472&cat%5B%5D=462&pricefrom=0&priceto=250&yearfrom=1985&yearto=2015&organics=&q=

Configuration

  • Add to composer (composer require ibrows/friendly-form-bundle)
  • Add to AppKernel (new Ibrows\FriendlyFormBundle\IbrowsFriendlyFormBundle())
  • Configure on your FormType as seen below
  • Use FriendlyFormExtensionService for handling request / submitting form data

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