M
M
Maxim Savichev2015-09-15 13:00:59
symfony
Maxim Savichev, 2015-09-15 13:00:59

Form and validation from a third-party service. How to do it right?

Good afternoon.
There was such a problem.
I have two bundles in symfony2.
In the first bundle, a form is created in the controller and displayed on the page
. I want to make the controller accept form values ​​in the second bundle.
First controller:

$form = $this->createFormBuilder($donut)
            ->add('sum','integer', array('label' => 'Сумма'
 ))
            ->getForm();

Second controller:
public function indexAction(Request $request)
    {
$all_sum = $sum*70;
}

I know that it can be done in one function of one controller by means of
if ($request->getMethod() == 'POST') {
                $form->bind($request);

But how to do it with another function and controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2015-09-15
@lexxpavlov

The form is created in the first bundle, but (in this case) not used, but is used in the second bundle? That is, the form uses Request in the controller in the second bundle?
Make the form a separate service , don't use the form builder in the controller. This, by the way, is generally more convenient - first create a form, and in the controller create it via $form = $this->createForm('my_form');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question