I'm using FOSUserBundle, I'm trying to validate email and username if they're already exist or not. Otherwise I get MySQL duplicate entry error.
I've extended the registration form, added the Registration
validation group. But still no good, I always get duplicate entry error.
Here's my RegistrationType
class:
class RegistrationType extends BaseType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
"data_class" => "Tsk\FEBundle\Entity\User",
"validation_groups" => array("Registration")
));
}
public function getName()
{
return "tsk_fe_registration_form_type";
}
}
And the service definition:
<parameters>
<parameter key="tsk_fe.registration.form.type.class">Tsk\FEBundle\Form\RegistrationType</parameter>
</parameters>
<services>
<service id="tsk_fe.registration.form.type" class="%tsk_fe.registration.form.type.class%">
<tag name="form.type" alias="tsk_fe_registration_form_type"/>
<argument>%fos_user.model.user.class%</argument>
</service>
</services>
In config.yml
:
fos_user:
db_driver: orm
firewall_name: main
user_class: Tsk\FEBundle\Entity\User
registration:
form:
type: tsk_fe_registration_form_type
And finally my User
entity:
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
* @ORM\HasLifecycleCallbacks
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
}
//..
}