0

I am experiencing the following form error in Symfony:

Neither the property "email" nor one of the methods "email()", "getemail()"/"isemail()"/"hasemail()" or "__call()" exist and have public access in class "Symfony\Component\Form\FormView".

This is what my form looks like:

My App\Form\LostPasswordType:

namespace App\Form;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use App\Entity\LostPassword;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\AbstractType;

class LostPasswordType extends AbstractType
{
    public function builder(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->setAction('/forgotpw')
            ->setMethod('POST')
            ->add('mail', EmailType::class, [
                'required' => true,
                'label'    => false,
                'attr'     => [
                    'autofocus' => false,
                    'class' => 'span8',
                    'placeholder' => '[email protected]'
                ]
            ])
            ->add('submit', SubmitType::class, [
                'label' => 'Reset Password',
                'attr' => ['class' => 'btn btn-primary btn-green']
            ])
        ;
    }

    public function configureOption(OptionsResolver $resolver)
    {
        $resolver->setDefaults(['data_class' => LostPassword::class]);
    }
}

And this is my controller code:

$formReset = $this->createForm(
    LostPasswordType::class,
    $forgotpass,
    array('csrf_protection' => false)
);
$formReset->handleRequest($request);

Does anyone know why I am receiving this error?

9
  • You added a property called 'mail' and are getting an error about 'email'. Hmmm. Commented Jun 6, 2018 at 0:01
  • That is form type, means i've added in my Entity functions for getEmail and setEmail. Commented Jun 6, 2018 at 0:08
  • 1
    Then why call it 'mail'? Commented Jun 6, 2018 at 0:10
  • 2
    Ah. Now I see what is going on. There are some people who enjoy posting questions where the code in the question does not match the actual code. Does make it challenging. Much easier when your posted code matches your actual code but oh well. Maybe someone else wants to play. Commented Jun 6, 2018 at 0:37
  • 1
    @Cerad is right: you must have a mismatch between forgotpass (whatever it is) and LostPasswordType. Please, post the actual code of both classes so when can help you. Moreover I would like to highlight that you're not behaving with the right constructive attitude that we, as a community, embrace and recommend. Commented Jun 6, 2018 at 10:56

1 Answer 1

1

I fixed the problem by changing the method function name in form builder, it was mistake there.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.