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(),
));
}
}