Reputation: 21
Using symfony 2.3 I'm trying to use a dumb form based on class form (without entity) like this:
SearchType.php
<?php
namespace Floarc\ParkingBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class SearchType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('search', 'text');
}
public function getName()
{
return 'search';
}
}
And this is what I got in my controller:
/**
* @Route("/search", name="_farc_search")
* @Template()
*/
public function searchAction(Request $request)
{
$form = $this->createForm(new SearchType());
$form->handleRequest($request);
return array('form' => $form->createView());
}
And in my view
{{ form(form) }}
Simple isn't it...
But when I display this page I get 2 fields displayed instead of only one!
Here is the code of the form:
<form name="search" method="post" action="">
<input type="search" id="search" name="search" required="required">
<div>
<label for="search_search" class="required">Search</label>
<input type="text" id="search_search" name="search[search]" required="required">
</div>
<input type="hidden" id="search__token" name="search[_token]" value="oMyq2WORCXyD97WKLb309F0pR1NpDkvVyi8FgqilUzo">
</form>
The field I've added has been named with the id="search_search" and a correct associated label, and of course I've got an input for the token.
But I do not understand where the input id="search"
came from?
Furthermore this input has no label?
Any ideas?
Upvotes: 1
Views: 257
Reputation: 20193
Maybe getName()
that returns "search" conflicts with built-in search
form type.
Try changing it to return something else...
Upvotes: 4