src/Form/RegistrationFormType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  8. use Symfony\Component\Form\FormBuilderInterface;
  9. use Symfony\Component\OptionsResolver\OptionsResolver;
  10. use Symfony\Component\Validator\Constraints\Email;
  11. use Symfony\Component\Validator\Constraints\IsTrue;
  12. use Symfony\Component\Validator\Constraints\Length;
  13. use Symfony\Component\Validator\Constraints\NotBlank;
  14. class RegistrationFormType extends AbstractType
  15. {
  16.     public function buildForm(FormBuilderInterface $builder, array $options): void
  17.     {
  18.         $builder
  19.             ->add('email'EmailType::class, [
  20.                 'attr' => [
  21.                     'class' => 'form-control',
  22.                     'placeholder' => 'Email'
  23.                 ],
  24.                 'constraints' => [
  25.                     new NotBlank([
  26.                         'message' => 'Please enter a email',
  27.                     ]),
  28.                     new Email([
  29.                         'message' => 'Please enter valid a email',
  30.                     ])
  31.                 ],
  32.             ])
  33.             ->add('companyName',  null,[
  34.                 'attr' => [
  35.                     'class' => 'form-control',
  36.                     'placeholder' => 'Company name'
  37.                 ]
  38.             ])
  39.             ->add('name',  null,[
  40.                 'attr' => [
  41.                     'class' => 'form-control',
  42.                     'placeholder' => 'Name'
  43.                 ]
  44.             ])
  45.             ->add('surname',  null,[
  46.                 'attr' => [
  47.                     'class' => 'form-control',
  48.                     'placeholder' => 'Surname'
  49.                 ]
  50.             ])
  51.             ->add('phone',  null,[
  52.                 'attr' => [
  53.                     'class' => 'form-control',
  54.                     'placeholder' => '(xxx)xxx-xxxx'
  55.                 ]
  56.             ])
  57.             ->add('plainPassword'PasswordType::class, [
  58.                 // instead of being set onto the object directly,
  59.                 // this is read and encoded in the controller
  60.                 'mapped' => false,
  61.                 'attr' => [
  62.                     'class' => 'form-control',
  63.                     'placeholder' => 'Password',
  64.                     'minlength' => "4"
  65.                 ],
  66.                 'constraints' => [
  67.                     new NotBlank([
  68.                         'message' => 'Please enter a password',
  69.                     ]),
  70.                     new Length([
  71.                         'min' => 6,
  72.                         'minMessage' => 'Your password should be at least {{ limit }} characters.',
  73.                         // max length allowed by Symfony for security reasons
  74.                         'max' => 4096,
  75.                     ]),
  76.                 ],
  77.             ])
  78.             ->add('agreeTerms'CheckboxType::class, [
  79.                 'mapped' => false,
  80.                 'attr' => [
  81.                     'class' => 'form-check-input',
  82.                 ],
  83.                 'label' => 'I have read and accept the  <a href="/privacy-policy">User agreement.</a>',
  84.                 'label_html' => true,
  85.                 'constraints' => [
  86.                     new IsTrue([
  87.                         'message' => 'You should agree to our terms.',
  88.                     ]),
  89.                 ],
  90.             ])
  91.         ;
  92.     }
  93.     public function configureOptions(OptionsResolver $resolver): void
  94.     {
  95.         $resolver->setDefaults([
  96.             'data_class' => User::class,
  97.         ]);
  98.     }
  99. }