Created
May 28, 2015 16:38
-
-
Save weaverryan/7d35a5511eab3b214a22 to your computer and use it in GitHub Desktop.
Creating a Symfony form with a country drop-down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(), | |
| )); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {{ 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