News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Court Ewing's Blog:
Create and Validate a Choice List in a Symfony 2 Form
August 17, 2011 @ 08:28:21

Court Ewing has written up a new post to his blog about creating a "choice" list (a select list as defined by Symfony 2) with dynamic options and validating the resulting submission. His example uses Doctrine 2 entities to work with most of the data handling.

A standard select list can be created using Symfony's choice field type; it is pretty clear how to create a new choice field with simple, non-dynamic options (e.g. gender), but it gets a little more complicated when you want to create and validate a dynamically generated choice list.

He includes the code for a simple entity, a Post model to fetch the category information and the set up of the form element - a select list of post types/categories. He also includes a bonus section showing how you can achieve the same thing without a model to bind to. The code's a little bit more complex than the previous example, but it's basically just reproducing some of the validation and fetching logic manually.

0 comments voice your opinion now!
create validate tutorial symfony2 form select choice dynamic


blog comments powered by Disqus

Similar Posts

Brandon Savage's Blog: Peer Review: You Have Not Because You Ask Not (Requests & Responses)

DevShed: Retrieving Information on Several Objects with Destructors in PHP 5

Oracle Technology Network: DeployPHP Series, Part 5 - Zend Core for Oracle Quick Start

Brian Swan's Blog: Using the Zend Framework and the PDO_SQLSRV Driver

php|architect: More powerful Validation from Respect


Community Events





Don't see your event here?
Let us know!


laravel series framework refactor developer release install symfony2 opinion list language code threedevsandamaybe introduction unittest community testing podcast api interview

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework