1

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.

2
  • 1
    It is described in the documentation. Commented Feb 24, 2012 at 1:06
  • i can't find the sentence where i can set the id. To override the template is not that what i want. Commented Feb 24, 2012 at 9:29

2 Answers 2

3

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)

Sign up to request clarification or add additional context in comments.

2 Comments

No, my name is "areaSelect", not "form".
Update your question with your template code, controller action and form if you want that i see the problem.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.