Skip to content

Instantly share code, notes, and snippets.

@weaverryan
Created May 28, 2015 16:38
Show Gist options
  • Select an option

  • Save weaverryan/7d35a5511eab3b214a22 to your computer and use it in GitHub Desktop.

Select an option

Save weaverryan/7d35a5511eab3b214a22 to your computer and use it in GitHub Desktop.
Creating a Symfony form with a country drop-down
<?php
class DefaultController
{
public function someAction(Request $request)
{
$form = $this->createFormBuilder()
->add('the_countries', 'country')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$country = $form['the_countries']->getData();
// do something with this country
// then eventually redirect
return $this->redirectToRoute('some_route');
}
return $this->render('default/someTemplate.html.twig', array(
'form' => $form->createView(),
));
}
}
{{ form_start(form) }}
{{ form_row('form.the_countries') }}
<button type="submit">Save Country</button>
{{ form_end(form) }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment