Всем привет! Создал класс формы
<?php
namespace App\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', TextType::class, [
'constraints' => [
new NotBlank(),
new Length(['min' => 30]),
]
])
->add('lastName', TextType::class)
->add('username', TextType::class)
->add('email', EmailType::class)
->add('imageFile', FileType::class)
->add('currentPassword', PasswordType::class, [
'mapped' => false
])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class
])
->add('submit', SubmitType::class);
}
}
код контроллера
/** @var User $user */
$user = $security->getUser();
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$userService->updateProfile($user);
$url = $this->generateUrl('fos_user_profile_show');
return new RedirectResponse($url);
}
пробовал даже создать валидацию в yml файле
FOS\UserBundle\Model\User:
properties:
plainPassword:
- Length:
min: 6
minMessage: fos_user.password.short
groups: [BugSquasherRegistration, BugSquasherResetting]
- Regex:
pattern: '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{6,}$/'
message: Password must have at least one uppercase letter, one lowercase letter, one number and one special character
groups: [BugSquasherRegistration, BugSquasherResetting]
App\Entity\User:
properties:
firstName:
- Length:
min: 30
Но ничего не валидируется, в чем моя ошибка?
P.S. Не использую аннотации