<?php
namespace App\Form;
use App\Entity\Newsletter;
use App\Entity\User;
use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordStrength;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', RepeatedType::class, [
'type' => emailType::class,
'attr' => ['class' => 'form-group'],
'invalid_message' => 'The email fields must match.',
'first_options' => ['label' => 'Email'],
'second_options' => ['label' => 'Repeat Email'],
])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'attr' => ['class' => 'form-group'],
'invalid_message' => 'The password fields must match.',
'required' => true,
'mapped' => false,
'first_options' => ['label' => 'Password'],
'second_options' => ['label' => 'Repeat Password'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new PasswordStrength([
'minLength' => 8,
'minStrength' => 3,
'message' => 'Your password must be at least 8 characters and include both upper and lowercase letters, and at least one number or symbol.'
]),
],
])
->add('forename', TextType::class, [
'label' => 'Forename(s)',
])
->add('surname', TextType::class, [
'label' => 'Surname',
])
->add('title', ChoiceType::class, [
'label' => 'Title',
'placeholder' => '- Please Select -',
'choices' => array_flip(User::TITLES),
])
->add('subscriptions', EntityType::class, [
'class' => Newsletter::class,
'label' => 'Email me updates on',
'choice_label' => 'title',
'expanded' => true,
'multiple' => true,
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}