Actually when I try to edit the form by sending empty fields, the above error comes on ,
My UserType class looks like:
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', null, [
'label' => 'Prénom'
])
->add('lastName', null, [
'label' => 'Nom'
])
->add('email', EmailType::class, [
'label' => 'Adresse e-mail'
])
->add('password', PasswordType::class, [
'label' => 'Mot de passe'
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}
This problem can be resolved by adding 'empty_data' param in the builder add function:
So the new UserType classe becomes:
class UserType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', null, [
'label' => 'Prénom',
**'empty_data' => ''**
])
->add('lastName', null, [
'label' => 'Nom',
**'empty_data' => ''**
])
->add('email', EmailType::class, [
'label' => 'Adresse e-mail',
**'empty_data' => ''**
])
->add('password', PasswordType::class, [
'label' => 'Mot de passe',
**'empty_data' => ''**
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With