craue / CraueFormFlowBundle

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

Lost data (object) at finish step #296

Open mateuszmalecki opened 7 years ago

mateuszmalecki commented 7 years ago

Hello. Please help me. I have code like this:

public function orderFromFileAction(Request $request){
        $formData = new Order();
        $flow = $this->get('app.form.flow.orderfromfile');
        $flow->bind($formData);

        $form = $flow->createForm();
        if ($flow->isValid($form)) {
            $flow->saveCurrentStepData($form);
            if ($flow->nextStep()) {
                $Form = new Form(); //Object named Form
                $Form->setLength(1000);
                $formData->addForm($Form); //Add object named form to object in $formData
                $form = $flow->createForm($formData);
                var_dump($formData->getForms()); 
                COMMENT: Test variable $formData->getForms(), it works
            } else {
                var_dump($formData->getForms()); 
                COMMENT: Test variable $formData->getForms(), in this moment my information will be lost, i  dont have all information about object and i cant add this to database

                $flow->reset();
                return $this->redirect($this->generateUrl('index')); 
            }
        };
        return array(
            'form' => $form->createView(),
            'flow' => $flow
        );

At first and second step everything is ok, but at third finish step my object Order don't have Forms objects in variable forms. var_dump return null. I don't know why. I can't save entity to database, only can save object Order but without Forms objects. This forms objects are elements created by SymfonyCollections. Link: https://github.com/ninsuo/symfony-collection

craue commented 7 years ago

Although this data transformation looks strange, it's done only temporarily before rendering the next step(s), but not when finishing the flow.

mateuszmalecki commented 7 years ago

so how can I save this data to finish step?

craue commented 6 years ago

Try getting this code out of the if ($flow->nextStep()) {...} block, so that it's called for each step (including the last one).