Wolf-Tech
Wolf-Tech

Reputation: 1309

symfony2 formbuilder

i created a customFormtype in symfony2 and i'm using it in a formbuilder in my controller. This is the html result when i render the form:

        <div id="form">
              <input type="hidden" id="form__token" name="form[_token]" value="2e8fe0d777b5c0d7d30d9bfd9d5143811c790b1d">
              <div>
                 <label class=" required">Stars</label>
                 <!-- some other stuff -->
              </div>
        </div>

Where does the id form came from and where can i change the name? Thank you very much.

Upvotes: 1

Views: 1388

Answers (2)

Eugene Leonovich
Eugene Leonovich

Reputation: 924

You may use a named form builder:

protected function createMyForm()
{
    return $this->container->get('form.factory')->createNamedBuilder('my_form_name', 'form')
        ->add('id', 'hidden')
        ->getForm();
}

Upvotes: 1

webda2l
webda2l

Reputation: 6708

The id of the form is defined by the getName() function

class TaskType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder->add('task');
        $builder->add('dueDate', null, array('widget' => 'single_text'));
    }

    public function getName()
    {
        return 'task';
    }
}

Ex. 'task' here. (http://symfony.com/doc/current/book/forms.html#creating-form-classes)

Upvotes: 3

Related Questions