I have a custom Doctrine object that I am trying to add to the form to validate the form, but they do not work for the registration form under any conditions.
My custom object:
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;
class User implements AdvancedUserInterface,\Serializable
{
private $id;
private $email;
private $username;
...
}
Here is my UserType form:
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->add('email','email');
$builder->add('username','text');
...
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'My\AppBundle\Entity\User',
'validation_groups' => array('registration'),
);
}
public function getName()
{
return 'user';
}
}
And finally, the registration form:
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->add('user', new UserType());
}
public function getName()
{
return 'registration';
}
}
It seems I should be missing something obvious here, but between the Symfony manual and the resources I found on the Internet, I was unable to determine what it was.
source
share