Skip to content

[Form] Support buttons in forms #5383

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
webmozart opened this issue Aug 30, 2012 · 1 comment
Closed

[Form] Support buttons in forms #5383

webmozart opened this issue Aug 30, 2012 · 1 comment

Comments

@webmozart
Copy link
Contributor

In my latest meeting with the Drupal people, we talked about their native support for buttons in forms which is currently missing in Symfony. They support things like:

  • Different buttons lead to different validation groups being executed. E.g. a "Previous" button in a multi-step form would not trigger validation, while a "Next" button would.
  • Support for adding/removing rows to/from a collection form using server round-trips when JavaScript is not available.

This ticket needs more research, but we should look into supporting these use cases in future releases.

@henrikbjorn
Copy link
Contributor

ref #5231

fabpot added a commit that referenced this issue Apr 17, 2013
This PR was merged into the master branch.

Discussion
----------

[2.3] [Form] Support buttons in forms

Bug fix: no
Feature addition: yes
Backwards compatibility break: yes
Symfony2 tests pass: yes
Fixes the following tickets: #5383
Todo: -
License of the code: MIT
Documentation PR: symfony/symfony-docs#2489

The general idea of this PR is to be able to add buttons to forms like so:

```php
$builder->add('clickme', 'submit');
```

You can then check in the controller whether the button was clicked:

```php
if ($form->get('clickme')->isClicked()) {
   // do stuff
}
```

Button-specific validation groups are also supported:

```php
$builder->add('clickme', 'submit', array(
    'validation_groups' => 'OnlyClickMe',
));
```

The validation group will then override the one defined in the form if that button is clicked.

This PR also introduces the disabling of form validation by passing the value `false` in the option `validation_groups`:

```php
$builder->add('clickme', 'submit', array(
    'validation_groups' => false,
));
```

The same can be achieved (already before this PR) by passing an empty array:
```php
$builder->add('clickme', 'submit', array(
    'validation_groups' => array(),
));
```

See the linked documentation for more information.

Commits
-------

faf8d7a [Form] Added upgrade information about setting "validation_groups" => false
d504732 [Form] Added leading backslashes to @exceptionMessage doc blocks
c8afa88 [Form] Removed deprecated code scheduled for removal in 2.3
36ca056 [Form] Simplified Twig code
ce29c70 [Form] Fixed incorrect doc comment
0bc7129 [Form] Fixed invalid use of FormException
600007b [Form] The option "validation_groups" can now be set to false to disable validation. This is identical to setting it to an empty array.
277d6df [Form] Fixed concatenation operator CS (see 7c47e34)
7b07925 [Form] Changed isset() to array_key_exists() to be consistent with ParameterBag
7b438a8 [Form] Made submit buttons able to convey validation groups
cc2118d [Form] Implemented support for buttons
@fabpot fabpot closed this as completed Apr 17, 2013
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