[1/3] Symfony 3 For Beginners - Part 2

13K views Feb 14, 2023

Towards the end of the previous section we had the foundations of our Contact Form implementation. In this section we are going to expand on this a little further, looking at: * extracting the set-up of our form into a separate class; * submitting forms to different controller actions; * displaying flash messages, and why you might want too; * potential 'gotchas' around redirects * customising the form with styles, labels, and options We're going to start by extracting out the creation of the Contact Form from our controller action into its own class. This class will be our "Form Type", or more specifically, our "Contact Form Type". In my experience, one of the most confusing parts of working with Symfony's Form Component is that the Form Type is not "the form". When working with HTML forms you can create your `input` elements and `textarea`'s, your `select`s and your `button`s. In Symfony you will never - directly - do this. Instead, you will use objects to describe your form, and behind the scenes the Form Component will convert this information into an HTML form representing what you described. This is less confusing when seen than it may sound currently. Now, even more strangely, you don't necessarily even need to render any HTML whatsoever to work with the Form Component. This is a more advanced topic, but if you continue with learning Symfony and move onto some of the more advanced setups such as a [JSON API][1] then you will more than likely encounter this. But you really needn't concern yourself with this at the moment. Find this full write up and the full course at CodeReviewVideos.com

#Forms Guides & Templates
  # General Reference