8000 Option to disable rendering name attribute to submit button · Issue #28964 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Option to disable rendering name attribute to submit button #28964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Ferikl opened this issue Oct 24, 2018 · 6 comments
Closed

Option to disable rendering name attribute to submit button #28964

Ferikl opened this issue Oct 24, 2018 · 6 comments

Comments

@Ferikl
Copy link
Ferikl commented Oct 24, 2018

Description
Add Possibility to not render name attribute to submit button (SubmitType).

Example

I want to create simple Search Form like this:

use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;

$form = $formFactory->createNamedBuilder(null, FormType::class, null, ['csrf_protection' => false])
            ->setMethod('GET')
            ->add('tag', TextType::class, ['label' => 'Tag name'])
            ->add('Search By Tags', SubmitType::class)

            ->getForm()
        ;

When I render my Form in template

{{ form_start(form) }}
{{ form_errors(form) }}
{{ form_end(form) }}

I can see:

<button type="submit" id="Search By Tags" name="Search By Tags" class="btn-secondary btn">Search By Tags</button>

But I dont want to have &Search+By+Tags= in my URL after form submit and Error with message:

ERROR This form should not contain extra fields.

So my suggestion is to add some param/option to SubmitType::class or whatever to NOT render name="Search By Tags" attribute.

@xabbuh
Copy link
Member
xabbuh commented Oct 24, 2018

I wonder why the extra fields error is thrown. Does this happen only when the form name contains a space?

@Ferikl
Copy link
Author
Ferikl commented Oct 24, 2018

I wonder why the extra fields error is thrown. Does this happen only when the form name contains a space?

yes

@xabbuh
Copy link
Member
xabbuh commented Oct 24, 2018

I think the issue here is that the ButtonBuilder does not validate the passed name. The FormConfigBuilder does this and while doing so forbids names containing a space.

@xabbuh
Copy link
Member
xabbuh commented Oct 24, 2018

@Ferikl So in your case the solution is to choose a name that does not contain spaces.

@Ferikl
Copy link
Author
Ferikl commented Oct 24, 2018

@Ferikl So in your case the solution is to choose a name that does not contain spaces.

I am not sure that it is what I want.
@xabbuh I want to have an option to not set name attribute to Submit button as I describe in the head of topic.

@xabbuh
Copy link
Member
xabbuh commented Oct 24, 2018

I don't think this is a use case that is common enough to justify an option for this in the Form component. IMO to achieve this you rather need to make use of the form theming mechanism in your application to make sure that the attribute is not rendered

@fabpot fabpot closed this as completed Feb 21, 2019
fabpot added a commit that referenced this issue Feb 21, 2019
This PR was merged into the 4.3-dev branch.

Discussion
----------

[Form] deprecate using invalid names for buttons

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #28964
| License       | MIT
| Doc PR        |

Commits
-------

405aa54 deprecate using invalid names for buttons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0