Skip to content

Instantly share code, notes, and snippets.

@j
Created May 28, 2011 03:20
Show Gist options
  • Save j/996556 to your computer and use it in GitHub Desktop.
Save j/996556 to your computer and use it in GitHub Desktop.
<?php
namespace JStout\MainBundle\Form\User;
use Symfony\Component\Form\Form;
class SignupHandler
{
protected $form;
public function __construct(Form $form)
{
$this->form = $form;
}
public function process()
{
// Form validation successful!... :)
if ($this->form->isValid()) {
... do all the uber cool user signup stuff ...
}
// Form validation failed... :(
return false;
}
}
<?php
namespace JStout\MainBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Template,
JStout\MainBundle\Entity\User,
JStout\MainBundle\Form\User\SignupType,
JStout\MainBundle\Form\User\SignupHandler;
/**
* @Route("/user")
*/
class UserController extends Controller
{
/**
* @Route(name="user")
* @Template()
*/
public function indexAction()
{
return array();
}
/**
* @Route("/sign-up", name="user_signup")
* @Template()
*/
public function signupAction()
{
$user = new User();
$form = $this->get('form.factory')->create(new SignupType(), $user);
$request = $this->get('request');
if ($request->getMethod() == 'POST') {
$form->bindRequest($request);
$formHandler = new SignupHandler($form);
if ($formHandler->process()) {
return $this->redirect($this->generateUrl('success');
}
}
return array(
'form' => $form->createView()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment