I try to custom the registration form of FOSUserBundle for the first time, following the documentation but when I submit the form, there is an error message that ask me to "enter the firstname" even when the field is not blank.
I am mistaking something and I don't know what. Here is my code:
src/AppBundle/Entity/User.php:
<?php
namespace AppBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="fos_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="firstname", type="string", length=255)
* @Assert\NotBlank(message="Please enter your first name.", groups={"Registration", "Profile"})
* @Assert\Length(
* min=3,
* max=255,
* minMessage="The name is too short.",
* maxMessage="The name is too long.",
* groups={"Registration", "Profile"}
* )
*/
protected $firstname;
// ...
public function getFirstname()
{
return $this->firstname;
}
public function setFirstname($firstname)
{
$this->$firstname = $firstname;
}
// ...
}
src/AppBundle/Form/RegistrationType.php:
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class RegistrationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('firstname', null, array(
'label' => false,
'translation_domain' => 'FOSUserBundle',
'attr' => array(
'placeholder' => 'form.firstname'
)
));
}
public function getParent()
{
return 'FOS\UserBundle\Form\Type\RegistrationFormType';
}
public function getBlockPrefix()
{
return 'app_user_registration';
}
}
My app/config/services.yml and app/config/config.yml are exactly the same as in the documentation.
What did I do wrong ? Thanks.
EDIT:
After some researches, it looks like the form doesn't fill well the User entity. If my firstname field is filled with Jason (for example), it will add a key to the Entity named Jason and filled with Jason and firstname will be null.
BUT, if the field is filled with firstname SO the firstname key will be filled with firstname and it will be saved into the DB:
