symfony - Symfony2 createFormBuilder field name prefix without entity -
a form has been created in symfony2 using createformbuilder, not need entity , used searching. name of form , input name need changed.
$form = $this->createformbuilder(null, array( 'action' => $this->generateurl('route'), 'method' => 'get', 'csrf_protection' => false, 'attr' => array('name' => 'search'), )) ->add('query', 'text', array( 'required' => false, )) ->getform();
the rendered html follows:
<form class="" method="get" action="route" name="form"> <div class="errors"></div> <div id="form" name="search"> <div> <label for="form_query">query</label> <input id="form_query" type="text" value="king" name="form[query]"> </div> </div> <p> </form>
how can form name changed? form, means div id form, changed search?
secondly input should have name query not form[query]?
i have had @ docs working form without entity can not see how change these properties.
the end result should be:
<form class="" method="get" action="route" name="search"> <div class="errors"></div> <div id="search"> <div> <label for="search_query">query</label> <input id="search_query" type="text" value="king" name="query"> </div> </div> <p> </form>
you should call createnamedbuilder
. allows set custom form name in first argument.
example:
// public function createnamedbuilder($name, $type = 'form', $data = null, array $options = array()) $form = $this->get('form.factory')->createnamedbuilder('', 'form', array(), array( 'action' => $this->generateurl('route'), 'method' => 'get', 'csrf_protection' => false, 'attr' => array('name' => 'search'), ))->add('query', 'text', array( 'required' => false, ))->getform();
for more useful methods, please see: \symfony\component\form\formfactory
Comments
Post a Comment