2
votes

I'm using submit form type in my FormType class (I want it to be customized for css classes and button label).

Since it's a search, I decided to go with GET, not default POST. What I noticed in Symfony2, is that:

I tried to remove auto-genarated HTML "name" attr from the "button / submit" HTML tag in controller, in form type class, and even in Twig template, e.g. by overriding "name" - nothing seems to work for Symfony2, and the name="submit" for this button is always generated.

It there a way to remove this HTML attr from submit button, or am I forced to only render whole submit button by myself, and remove it from Form Type class?

Template for the search form is very basic, nothing extraordinary for Symfony2:

    {{ form_start(form) }}
        <div>
            {{ form_widget(form.target) }}
        </div>
        <div>
            {{ form_widget(form.phrase) }}
            {{ form_widget(form.submit) }}
        </div>
        {{ form_errors(form) }}
    {{ form_end(form) }}

And for the form type, I use standard submit:

$builder->add('submit', 'submit', array('label' => 'search', attr(name => null) ....)

As you see, here name attr is explicilty set to null. Symfony2 generate it any way, and give it a "submit" value to this 'name' attr.

The only problem is: can I make somehow Symfony2 to NOT generate "name" attr in the HTML Button/Submit tag? If Symfony2 cannot do that, it seems that the only way is to simply remove "submity" from Form Type class, and put HTML for this button directly in the template by myself, which I'm trying to not do (but if it's not possible, I will have to).

To me, it seems like it's a problem with Symfony2. Submit type is quite new thing in forms here, and I can imagine that auto-generated "name" attr follows the same rules as other form types in Symfony2 - although it is really not needed in HTML forms!

SOLUTION: So, I ended up with rendering it all by myself, and removed it from Form Type. Still I think Symfony2 shouldn't generate 'name' for this particular tag - I saw never ever "name" attr being assigned to SUBMIT button HTML tag in any form on the web, it's obviously not needed and not desired.

1
You should post some code, like the form and the templateSplendonia
Ok, I put the code, though it's just a standard Symfony2 form. The main point is the "submit" form type, which seems to put "name" attr in Symfony2 when auto-generated - and it is really not needed in HTML forms.forsberg

1 Answers

1
votes

I think there are three solutions:

  1. Have a form without the submit button and create the button outside of the form. Then submit the form with JS.

  2. Override the default twig template responsible for generating HTML content of the submit button.

  3. Generate the HTML content by yourself and not use the name there.