src/Form/UserRegistrationType.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\Users;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\FormBuilderInterface;
  6. use Symfony\Component\OptionsResolver\OptionsResolver;
  7. use Symfony\Component\Validator\Constraints\Length;
  8. use Symfony\Component\Validator\Constraints\Regex;
  9. use Symfony\Contracts\Translation\TranslatorInterface;
  10. /**
  11.  * Class UserRegistrationType
  12.  * @package App\Form
  13.  */
  14. class UserRegistrationType extends AbstractType
  15. {
  16.     /**
  17.      * @var Translator
  18.      */
  19.     protected $translator;
  20.     /**
  21.      * AuctionVehiclesBiddingType constructor.
  22.      * @param Translator|null $translator
  23.      */
  24.     public function __construct(TranslatorInterface $translatornull)
  25.     {
  26.         $this->translator $translator;
  27.     }
  28.     /**
  29.      * @param FormBuilderInterface $builder
  30.      * @param array $options
  31.      */
  32.     public function buildForm(FormBuilderInterface $builder, array $options)
  33.     {
  34.         $locale $options['locale'];
  35.         $trans  $this->translator;
  36.         $mobValidation   $trans->trans('you should add your mobile number', [], 'validators');
  37.         $builder->add('mobileNumber'null, array(
  38.             'label'              => 'Mobile Number',
  39.             'translation_domain' => 'messages',
  40.             'required'           => true,
  41.             'constraints'        => array(
  42.                 new Length(array('min' => 9'max' => 10)),
  43.                 new Regex('/^(0)?5[0-9]{8}$/')
  44.             ),
  45.             'attr' => [
  46.                 'minlength'    => 9,
  47.                 'maxlength'    => 10,
  48.                 'pattern'      => '^(0)?5[0-9]{8}$',
  49.                 'validate-msg' => $mobValidation,
  50.                 'class'        => 'form-control',
  51.                 'placeholder'  => '5xxxxxxxx'
  52.             ]
  53.         ));
  54.         $builder->add('userIdentityInfo'UserRegistrationIdentityInfoType::class, array(
  55.             'label'  => false,
  56.             'locale' => $locale
  57.         ));
  58.     }
  59.     /**
  60.      * {@inheritdoc}
  61.      *
  62.      * @param OptionsResolver $resolver
  63.      */
  64.     public function configureOptions(OptionsResolver $resolver)
  65.     {
  66.         $resolver->setDefaults(array(
  67.             'data_class'         => Users::class,
  68.             'translation_domain' => 'clients',
  69.             'locale'             => 'en',
  70.             'csrf_protection' => true,
  71.             'csrf_field_name' => '_token',
  72.             // important part; unique key
  73.             'csrf_token_id'   => 'form_intention',
  74.         ));
  75.     }
  76.     /**
  77.      * {@inheritdoc}
  78.      *
  79.      * @return null|string
  80.      */
  81.     public function getBlockPrefix()
  82.     {
  83.         return 'appbundle_users_registration';
  84.     }
  85. }