Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

SymfonyCasts

Symfony 4 Forms: Build, Render & Conquer!

via SymfonyCasts

Overview

Yep, forms! One of the most powerful and... confusing features in all of Symfony. Here's the truth: forms are just plain hard. You need to manage the HTML form elements, validation, data transformation and a lot more. The Form component might be the most complex part of Symfony. But the more you work with it, the more you'll like it.

So, let's work with some forms! We'll learn how to use Symfony forms to handle both simple & complex/ugly situations. Most importantly, I'll show you how to avoid the pitalls that many developers often fall into that causes the form component to spiral into complexity hell. The form system is a tool: in this tutorial, we'll put the joy back into it:

  • Creating a basic form
  • Basic form rendering and customization
  • Handling a form submit
  • Backing your form with an entity
  • Adding validation
  • Filling with default data
  • Creating a form "type" class
  • Understanding how forms really work
  • Flash messages

... and bad jokes + form tips & tricks!

Syllabus

  • Form Type Class
  • Handling the Form Submit
  • Success (Flash) Messages
  • Bind Your Form to a Class
  • Field Types & Options
  • DateTimeType & Data "Transforming"
  • EntityType: Drop-downs from the Database
  • EntityType: Custom Query
  • HTML5 & "Sanity" Validation
  • Validation Constraints with @Assert
  • Form Rendering Functions: form_*
  • Form Rendering Variables
  • The Edit Form
  • Registration Form
  • Adding Extra "Unmapped" Fields
  • UniqueEntity & Validation Directly on Form Fields
  • Agree to Terms Database Field
  • Agree to Terms Checkbox Field
  • All about Form Themes
  • Form Theme Block Naming & Creating our Theme!
  • Form Theming & Variables
  • Form Theming a Single Field
  • Custom Field Type
  • Data Transformer
  • Custom Field: configureOptions() & Allowing Empty Input
  • Leveraging Custom Field Options
  • Autocomplete JavaScript
  • Autocomplete Endpoint & Serialization Group
  • Hooking up the AJAX Autocomplete
  • The buildView() Method
  • Form Type Extension
  • Tweak your Form based on the Underlying Data
  • Form Model Classes (DTOs)
  • Custom Validator
  • Setup: For Dependent Select Fields
  • Form Events & Dynamic ChoiceType choices
  • Dynamic Form Events
  • PRE_SET_DATA: Data-based Dynamic Fields
  • JS to Auto-Update the Select Options
  • Clear that Location Name Data
  • A bit of Security Cleanup

Taught by

Ryan Weaver

Reviews

Start your review of Symfony 4 Forms: Build, Render & Conquer!

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.