Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Symfony2 Essentials

You're reading from   Symfony2 Essentials

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781784398767
Length 158 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

Validation and form processing


So far, we have discussed the process of form creation. After we create the form, we usually need to validate the data provided, and we need to save the date somewhere. With Symfony2, these steps are pretty easy.

To make validation possible, we need to define rules for it. In Symfony2, we can define them in several ways. You can define constraints within the entity field (using annotations), within the form (as constraints option), and you can create validation YML configuration files. You should choose the way best for your own project clarity.

The easiest method is to provide validation within the form type, but again, it's not the best place to put constraints in (although it's useful if you are not using entities). If we work with entities, the best practice seems to be keeping the validation rules in the same place where we define the entity field.

Let's modify our entity class to support validation and make the name field required. Let's modify our entity...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image