This patch gives the ability to set the property #executes_validate_callback to buttons.
If a pressed button has this property set to FALSE then the form isn't validated.

With this patch forms can have buttons that cancel or add fields to the form, even if all data isn't properly filled in yet.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vanhanit’s picture

FileSize
3 KB

Sorry, one char wrong in the previous submission.
The corrected patch is attached.

drumm’s picture

Version: 5.3 » 7.x-dev
Status: Needs review » Needs work

New features only go into Drupal 7 now. Drupal 5 is the stable release, and 6 is feature frozen.

Please review and follow http://drupal.org/coding-standards.

You can also check for what button was pressed in your #validate and skip setting errors when applicable.

vanhanit’s picture

Sure you could check which button was pressed but the automatic validation still takes place (the "required" validation).
I will, if I get some time, check my code and rewrite it according to the Drupal coding standards.

vanhanit’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
2.98 KB

I have now completed the patch and tested it for a period of time without any problems.
Rewritten so that it follows the coding standard.

Gábor Hojtsy’s picture

Status: Reviewed & tested by the community » Needs review

What about waiting for someone else to test as well. Setting your own patch RTBC is not considered a good idea.

vanhanit’s picture

Well, who will test this patch then?
The changes aren't that big, so places where bugs can occure are minimal.

And as I wrote before, I have used this patch on many versions of Drupal 5 and there haven't been any problems yet.

Anyhow, if someone want's to be able to override the validation on some buttons this patch allows you to do just that.
This also disables the core validation (required fields etc).

Usage:

$form['button'] = array(
  '#type' => 'button',
  '#value' => t('Test'),
  '#executes_validate_callback' = FALSE,
);
Robin Monks’s picture

Status: Needs review » Needs work

Tabs are used in this patch, please refer to http://drupal.org/coding-standards .

Robin

vanhanit’s picture

FileSize
3 KB

Ok, tabs replaced with spaces...

vanhanit’s picture

Status: Needs work » Needs review
Anonymous’s picture

Status: Needs review » Needs work

isset($form['#executes_validate_callback']) == FALSE
should be
!isset($form['#executes_validate_callback'])

Is #executes_validate_callback the correct item for this? Why not change #validate (and #submit) to accept FALSE as one of its values. I think #executes_submit_callback and #executes_validate_callback are just egregious and don't give proper meaning to their function. The FAPI is already large and adding items when a value of FALSE would work just as well is hideous. Besides, the coding should be cleaner with fewer FAPI items.

effulgentsia’s picture

Version: 7.x-dev » 8.x-dev

For D7, we now have #limit_validation_errors, so you can set '#limit_validation_errors' => array(): #370537: Allow suppress of form errors (hack to make "more" buttons work properly). For D8, FAPI needs major re-work: #370537-99: Allow suppress of form errors (hack to make "more" buttons work properly).

attiks’s picture

The problem with #limit_validation_errors is that it's hard for other modules to detect what the purpose of the limiting is, we need to be able to detect if we need to add clientside validation or not, simply looking at #limit_validation_errors isn't working for us

We created a new feature request as well, see #1244862: Add #skip_validation property to 'Delete', 'Cancel' buttons

lmeurs’s picture

#11 works for me, thanks!

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

Searching current repo for executes_validate_callback and I don't see any instances. Believe this doesn't apply to D10

But if I'm wrong please reopen updating issue summary for D10

Thanks!