Skip to content

Instantly share code, notes, and snippets.

@wouterj
Created May 24, 2015 14:50
Show Gist options
  • Save wouterj/3eb7952d0f9f8df767b3 to your computer and use it in GitHub Desktop.
Save wouterj/3eb7952d0f9f8df767b3 to your computer and use it in GitHub Desktop.
<?php
// ...
class MyController extends Controller
{
/**
* @Route("/", name="neuro_index")
*/
public function indexAction()
{
$form = $this->createDonationForm();
$amount = 0;
$percentage = $amount / 6;
return $this->render('AppBundle:NeuroFund:index.html.twig', array(
'progress_amount' => $amount,
'progress_percentage' => $percentage,
'form' => $form->createView(),
));
}
/**
* @Route("/donate", name="neuro_save_form")
*/
public function donateFormAction(Request $request)
{
$form = $this->createDonationForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// yah! Let's handle the form submission and return some response
}
// ah, form wasn't valid, render it again with the errors...
return $this->render('AppBundle:NeuroFund:index.html.twig', array(
'progress_amount' => $amount,
'progress_percentage' => $percentage,
'form' => $form->createView(),
));
}
protected function createDonationForm()
{
$dform = new DonationForm();
return $this->createFormBuilder($dform)
->setAction($this->generateUrl('neuro_save_form'))
->add('name', 'text')
->add('email', 'email')
->add('bankaccountnumber', 'text')
->add('isanonymous', 'checkbox', array('required' => false))
->add('donate', 'submit', array('label' => 'Donate!'))
->getForm();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment