1

Ok it is probably something simple but i just cant find where the problem is. I have tried with but no match for my problem

I am trying to create from but from form class, not create form in controller..

here is the code..

this is from controller

    /**
 * @Route("login", name="login")
 */
public function loginAction (Request $request) {
    $registration = new Registration();

    $form = $this->createForm(LoginForm::class, $registration, array(
        'method' => 'POST'
    ));

    return $this->render(
        'admin/login.html.twig',
        array('form' => $form->createView())
    );
}

Inside controller i used USE to defind LoginForm i use in part createForm, so that is not problem

this is from FORM class

<?php

namespace AppBundle\AppForm;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;

class LoginForm extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('name')
        ->add('password')
        ->add('save', SubmitType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults(
        array(
          'data_class' => 'AppBundle\Entity\Registration'
        ));
}

public function getName()
{

}
}
5
  • 2
    And... What is your question? What are the errors? Commented Dec 1, 2015 at 15:06
  • in vendor\symfony\symfony\src\Symfony\Component\Form\FormRegistry.php at line 83 - } if (!$type) { throw new InvalidArgumentException(sprintf('Could not load type "%s"', $name)); } $this->resolveAndAddType($type); Commented Dec 1, 2015 at 15:10
  • What version of Symfony you use? Check it accurately. Commented Dec 1, 2015 at 15:11
  • Could not load type "AppBundle\AppForm\LoginForm" Commented Dec 1, 2015 at 15:11
  • Symfony version 2.7.7 Commented Dec 1, 2015 at 15:12

1 Answer 1

6

Your problem in Symfony version. You use code from Symfony3 while really have Symfony2.

Change SubmitType::class to submit, LoginForm::class to new LoginForm() and all will work fine.

Or you can update your Symfony version and all will work fine with your current code.

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

3 Comments

Yep. The upgrade to S3 is going to be fun fun fun since all the existing links to the 'current' documentation will now point to incorrect S2.x information.
thank you, problem is solved, i am folowing Symfony documentation step by step so it's not my fault..
It is because Symfony 3.0.0 was released yesterday (symfony.com/blog/symfony-3-0-0-released). And now all documentation point to current (3.0) version. But you started your project some days ago and installed Symfony 2.7 instead.

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.