<?php
namespace App\Form;
use App\Entity\Users;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Contracts\Translation\TranslatorInterface;
/**
* Class UserRegistrationType
* @package App\Form
*/
class UserRegistrationType extends AbstractType
{
/**
* @var Translator
*/
protected $translator;
/**
* AuctionVehiclesBiddingType constructor.
* @param Translator|null $translator
*/
public function __construct(TranslatorInterface $translator= null)
{
$this->translator = $translator;
}
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$locale = $options['locale'];
$trans = $this->translator;
$mobValidation = $trans->trans('you should add your mobile number', [], 'validators');
$builder->add('mobileNumber', null, array(
'label' => 'Mobile Number',
'translation_domain' => 'messages',
'required' => true,
'constraints' => array(
new Length(array('min' => 9, 'max' => 10)),
new Regex('/^(0)?5[0-9]{8}$/')
),
'attr' => [
'minlength' => 9,
'maxlength' => 10,
'pattern' => '^(0)?5[0-9]{8}$',
'validate-msg' => $mobValidation,
'class' => 'form-control',
'placeholder' => '5xxxxxxxx'
]
));
$builder->add('userIdentityInfo', UserRegistrationIdentityInfoType::class, array(
'label' => false,
'locale' => $locale
));
}
/**
* {@inheritdoc}
*
* @param OptionsResolver $resolver
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Users::class,
'translation_domain' => 'clients',
'locale' => 'en',
'csrf_protection' => true,
'csrf_field_name' => '_token',
// important part; unique key
'csrf_token_id' => 'form_intention',
));
}
/**
* {@inheritdoc}
*
* @return null|string
*/
public function getBlockPrefix()
{
return 'appbundle_users_registration';
}
}