Note that there are some explanatory texts on larger screens.

plurals
  1. POValidation constraints do not trigger for registration form
    text
    copied!<p>I have a Doctrine user entity that I am trying to add form validators to for the registration form but they do not fire for the registration form under any condition. </p> <p>My user entity:</p> <pre><code>namespace JMSHockey\AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Security\Core\User\AdvancedUserInterface; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * My\AppBundle\Entity\User * * @ORM\Table(name="user") * @ORM\Entity(repositoryClass="My\AppBundle\Entity\UserRepository") * @UniqueEntity(fields={"email"}, message="Sorry, this email address is already in use.", groups={"registration"}) * @UniqueEntity(fields={"username"}, message="Sorry, this username is already taken.", groups={"registration"}) */ class User implements AdvancedUserInterface,\Serializable { /** * @var integer $id * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string $email * * @ORM\Column(name="email", type="string", length=75, nullable=false) * @Assert\Email() * @Assert\NotBlank() */ private $email; /** * @var string $username * * @ORM\Column(name="username", type="string", length=75, nullable=false) * @Assert\NotBlank() */ private $username; ... } </code></pre> <p>Here's my UserType form:</p> <pre><code>namespace My\AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class UserType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('email','email'); $builder-&gt;add('username','text'); ... } public function getDefaultOptions(array $options) { return array( 'data_class' =&gt; 'My\AppBundle\Entity\User', 'validation_groups' =&gt; array('registration'), ); } public function getName() { return 'user'; } } </code></pre> <p>And lastly, the registration form:</p> <pre><code>namespace My\AppBundle\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; class RegistrationType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('user', new UserType()); } public function getName() { return 'registration'; } } </code></pre> <p>It seems like I must be missing something obvious here, but between the Symfony manual and the resources I've found online, I haven't been able to determine what it is. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload