craue / CraueFormFlowBundle

Multi-step forms for your Symfony project.
MIT License
736 stars 118 forks source link

Passing options to buildForm #240

Closed ValBrunhes closed 8 years ago

ValBrunhes commented 8 years ago

Hi, I'm a beginner with symfony and I'm trying to pass a value from my controller to my buildForm like this: http://stackoverflow.com/questions/29811837/symfony2-passing-options-to-buildform but it doesn't work. Any tips how could i resolve this issue?

ValBrunhes commented 8 years ago

$formData = new CreateVisite(); $flow = $this->get('spanc.form.flow.visite'); $flow->bind($formData); $form = $flow->createForm(VisiteType::class, $formData, ['id' => $id]);`

Sorry here is my code

craue commented 8 years ago

For 2.1, createForm has only one argument $options. For upcoming 3.0, see https://github.com/craue/CraueFormFlowBundle#passing-generic-options-to-the-form-type.

andrzejdziekonski commented 8 years ago

If i use method: $flow->setGenericFormOptions(array('action' => 'targetUrl'));

how can i fetch the parameter inside step forms or inside the flow (so i can pass it to form types via form_options)?

craue commented 8 years ago

@andrzejdziekonski, these options will be passed to the form type of each step. You don't need to pass them manually.

andrzejdziekonski commented 8 years ago

I see. What about third party parameters? Let's say i need to pass some parameter (i.e. 'locale') for my first step form field to filter collection with this param. With setGenericFormOptions method i get error that option '...' does not exist. What is the best way to achieve that?

craue commented 8 years ago

@andrzejdziekonski, see https://github.com/craue/CraueFormFlowBundle#passing-step-based-options-to-the-form-type.

andrzejdziekonski commented 8 years ago

I know i can pass parameters to form via form_options but question is how to pass dynamic ('locale' param is depending on user geo) parameter from controller to flow since i create the flow instance from service?

craue commented 8 years ago

@andrzejdziekonski, then you'd need to override getFormOptions as shown in the section mentioned previously.