Skip to content

Instantly share code, notes, and snippets.

@havvg
Created March 8, 2012 15:54
Show Gist options
  • Save havvg/2001639 to your computer and use it in GitHub Desktop.
Save havvg/2001639 to your computer and use it in GitHub Desktop.
CraueFormFlowBundle fill previous data when navigating steps
<?php
namespace Ormigo\Bundle\UserBundle\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\RegistrationController as Controller;
class RegistrationController extends Controller
{
// .. some more actions
public function merchantWizardAction()
{
$formData = $data = array(); // Should be some actual data model
/* @var $flow \Craue\FormFlowBundle\Form\FormFlow */
$flow = $this->container->get('ormigo_user.form.merchant_register_wizard.flow');
$flow->bind($data);
// Retrieve form data for the current step
if ($flowData = $this->container->get('session')->get($flow->getSessionDataKey())) {
if (!empty($flowData[$flow->getCurrentStep()])) {
$formData = $flowData[$flow->getCurrentStep()];
}
}
// Form of the current step
$form = $flow->createForm($formData);
if ($flow->isValid($form)) {
$flow->saveCurrentStepData();
if ($flow->nextStep()) {
$formData = array(); // Should be initialized according to the data model
// Refresh form data based on the new step
if (!empty($flowData[$flow->getCurrentStep()])) {
$formData = $flowData[$flow->getCurrentStep()];
}
// Form for the next step
$form = $flow->createForm($formData);
} else {
// Last step done!
// Persist data, send emails, push messages, you name it ..
}
}
return $this->container->get('templating')->renderResponse('UserBundle:Registration:register_merchant_wizard.html.'.$this->getEngine(), array(
'form' => $form->createView(),
'flow' => $flow,
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment