<?php
namespace App\Form;
use App\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\IsTrue;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Rollerworks\Component\PasswordStrength\Validator\Constraints\PasswordRequirements;
use Karser\Recaptcha3Bundle\Form\Recaptcha3Type;
use Karser\Recaptcha3Bundle\Validator\Constraints\Recaptcha3;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
'label_attr' => ['class' => 'uk-form-label'],
'attr' => ['autocomplete' => 'email', 'class' => 'uk-input'],
'constraints' => [
new NotBlank([
'message' => 'Please enter your email',
]),
],
])
->add('agreeTerms', CheckboxType::class, [
'mapped' => false,
'label' => 'I agree to the website\'s <a href="/privacy" target="_blank">Terms & Conditions</a> for creating account.',
'label_html' => true,
'label_attr' => ['class' => 'uk-form-label'],
'attr' => ['class' => 'uk-checkbox uk-margin-small-left'],
'constraints' => [
new IsTrue([
'message' => 'You should agree to our terms.',
]),
],
])
->add('plainPassword', PasswordType::class, [
// instead of being set onto the object directly,
// this is read and encoded in the controller
'mapped' => false,
'label_attr' => ['class' => 'uk-form-label'],
'attr' => ['autocomplete' => 'new-password', 'class' => 'uk-input'],
'constraints' => [
new NotBlank([
'message' => 'Please enter a password',
]),
new Length([
'min' => 8,
'minMessage' => 'Your password should be at least {{ limit }} characters',
// max length allowed by Symfony for security reasons
'max' => 25,
]),
new PasswordRequirements([
'requireLetters' => true,
'requireCaseDiff' => true,
'requireNumbers' => true,
'requireSpecialCharacter' => true,
])
],
])
->add('captcha', Recaptcha3Type::class, [
'constraints' => new Recaptcha3(),
'action_name' => 'register',
//'script_nonce_csp' => $nonceCSP,
])
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}