FOSUserBundle no validation made
I've created a User class in my Bundle based on FOSUserBundleModelUserBaseUser to register my users.
Here is my User.php :
class User extends BaseUser
{
/**
* @var integer
*
* @ORMColumn(name="id", type="integer")
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
*/
protected $id;
// Constructor
public function __construct()
{
parent::__construct();
// your own logic
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
}
Here is my UserType.php :
class UserType extends AbstractType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('valider', 'submit')
;
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'CSW78BundleEntityUser'
));
}
public function getParent()
{
return 'fos_user_registration';
}
/**
* @return string
*/
public function getName()
{
return 'user';
}
}
I overrode register.html.twig, putting it in /app/resources/FOSUserBundle/views/Registration and it is called. Here is my register.html.twig :
{% block body %}
<div id="cadre" class="arrondi">
<h1>Inscription</h1>
<br>
{% block fos_user_content %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register form-horizontal">
<div id="fos_user_registration_form">
<div class="form-group">
{{ form_label(form.username, 'Identifiant :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.username, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.email, 'Email :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.email, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.plainPassword.first, 'Mot de passe :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.plainPassword.first, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
<div class="form-group">
{{ form_label(form.plainPassword.second, 'Mot de passe (confirmation) :', {'label_attr': {'class': 'col-xs-5 col-sm-4 col-md-3 col-lg-3 control-label'}}) }}
<div class="col-xs-7 col-sm-8 col-md-5 col-lg-5">
{{ form_widget(form.plainPassword.second, {'attr': {'class': 'form-control'}}) }}
</div>
</div>
{{ form_widget(form._token, {'attr': {'class': 'form-control'}}) }}
{{ form_widget(form.valider, {'attr': {'class': 'btn btn-info btn-responsive btn-color'}}) }}
{{ form_end(form) }}
</div>
</form>
{% endblock %}
</div>
{% endblock %}
The problem is there is no validation made when I click on the submit button.
I thought that the validation constraints would inherit from the BaseUser validation constraints.
Is there something else to specify to call the BaseUser validation constraints on my User object ?
Another question: what if I want to customize the error messages, should I override the validation.xml file to do that ?
Thank you.
David
链接地址: http://www.djcxy.com/p/91686.html上一篇: 处理FOSUserBundle PlainPassword字段
下一篇: FOSUserBundle未进行验证