use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\EmailType; class ContactFormBuilder implements FormBuilderInterface { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name', TextType::class) ->add('email', EmailType::class) ->add('message', TextType::class); } }
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Validator\Constraints\NotBlank; class ContactFormBuilder implements FormBuilderInterface { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('name', TextType::class, [ 'constraints' => [new NotBlank()], ]) ->add('email', EmailType::class, [ 'constraints' => [new NotBlank()], ]) ->add('message', TextType::class, [ 'constraints' => [new NotBlank()], ]); } }In this example, we add constraints to the form fields to ensure that they are not blank when submitted. This helps validate the form data and ensure that the form is filled out properly before submission.