5

I want to create a form in Symfony2, so I followed the tutorial on this site

namespace Project\Foo\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Project\Foo\Entity\Anfrage;
use Symfony\Component\HttpFoundation\Request;

class UploadController extends Controller
{

public function indexAction(Request $request)
{
    $anfrage = new Anfrage();
    $anfrage->setName('Güntaa');
    $anfrage->setAge(5);
    $anfrage->setEmail('foo@foo.de');

    $form = $this->createFormBuilder($anfrage)
        ->add('save', 'submit', array('label' => 'Create Task'))
        ->getForm();

    return $this->render(
        'Foo:Upload:index.html.twig',
        array(
            'title' => 'Foo',
            'form' => $form->createView(),
        ));
    }
}

In my template I want to call this form:

{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

But when I call my template, I get the following error:

Validator must be instance of Symfony\Component\Validator\Validator\ValidatorInterface or Symfony\Component\Validator\ValidatorInterface

I don't know, how to solve this problem.

Edit

Here is the Anfrage's entity:

<?php   

namespace Project\MarkupConverterBundle\Entity;

class Anfrage {

    protected $name;
    protected $age;
    protected $email;

    public function getName()
    {
        return $this->name;
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    public function getAge()
    {
        return $this->age;
    }

    public function setAge($age)
    {
        $this->age = $age;
    }

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->$email = $email;
    }
}

Edit2

When I try to use the form without a class, I get the same error

namespace Project\Foo\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class UploadController extends Controller
{

public function indexAction(Request $request)
{
    $defaultData = array('message' => 'The message from you');

    $form = $this->createFormBuilder($defaultData)
        ->add('message', 'text')
        ->add('save', 'submit', array('label' => 'Create Task'))
        ->getForm();

    $form->handleRequest($request);

    if ($form->isValid()){
        $data = $form->getData();
    }

    return $this->render(
        'Foo:Upload:index.html.twig',
        array(
            'title' => 'Foo',
            'form' => $form->createView(),
        ));
    }
}
Nitaco
  • 51
  • 3
  • Uploaded it on pastebin, because I didn't know how to format it here: http://pastebin.com/bEithgRD – Nitaco Jan 07 '15 at 08:37
  • whats the version of symfony ?? – kskaradzinski Jan 07 '15 at 08:58
  • symfony 2.5.7 is mine – Nitaco Jan 07 '15 at 09:00
  • http://stackoverflow.com/questions/24009719/problems-with-validatorconstraint-in-symfony-2-5 maybe this will help You – kskaradzinski Jan 07 '15 at 09:03
  • Thanks, but it doesn't work – Nitaco Jan 07 '15 at 09:09
  • Can nobody help me? It's really urgently, otherwise I can't develop any form.. – Nitaco Jan 07 '15 at 10:18
  • @LuBeu Look at the `Stack Trace (Plain Text)` (in dev env.) section in error page, it shows which methods have been called. May be you can find something there.. – xurshid29 Jan 07 '15 at 11:55
  • Nothing helpful found – Nitaco Jan 07 '15 at 12:40
  • 2
    Do you have a Resources/config/validation.yml file? If so, post it. If not then you are either not using the code you have shown (which happens more frequently than you might think) or you have additional bundles which are improperly configured. And comment out the form_widget line in your template. It's not doing what you think. Consider also making a new project and working through the form chapter in the documentation. – Cerad Jan 07 '15 at 15:22
  • Okay, first I don't added an validation.yml. I put much time in debugging my application and tried many things to find the problem. Before I already added a Command for my application. I developed my own Validator in the same bundle and it looks the Symfony-Own-Validator for Forms is using my own Validator with his own Interface etc., but my own Validators don't go with the Symfony-Validator-Interface. Look: [Own Validators](http://abload.de/img/imagepuj2b.png) @Cerad – Nitaco Jan 12 '15 at 08:09
  • I don't understand what you mean by "developed my own Validator". The code you posted has no validation mapping information so just having these classes will not impact anything. Did you try to add your validator as a service? Are you using the validator.constraint_validator tag somehwere in a service.yml file? At this point, what you are posting just does not add up. Missing a key piece somewhere. I really think you should start with a new project, get a demo form working then bring in your custom bundles. – Cerad Jan 12 '15 at 12:05
  • I don't added validator.constraint_validator. – Nitaco Jan 12 '15 at 13:46

1 Answers1

0

Problem solved: My services name was Validator. Not really a good idea. Thank's to all who tried to help.

Nitaco
  • 51
  • 3