[development] D7 AJAX API change: Submit and Validation

Alex Bronstein alex at craftyspace.com
Sat Mar 27 00:45:13 UTC 2010

Small clarification to this: #1 and #2 are true for when the triggering 
element is not a submit button or image button (or more precisely, when 
its #executes_submit_callback property isn't true, which by default is 
only for submit buttons and image buttons). So for example, when 
clicking a checkbox directly triggers AJAX. When an AJAX-enabled submit 
or image button triggers an AJAX submission, then by default, validation 
errors are reported and either the button's #submit handlers or the 
FORM_ID_submit() function do get executed as you're used to from D6 
AHAH. In D7, a button can set #submit and #limit_validation_errors to 
empty arrays in order act the same as a non-button in this regard.

Hopefully, D7 FAPI and AJAX documentation will help make all this 
clearer. Randy, can you please send the documentation link you intended 
to send in the PS. The issue URL got pasted instead.


Randy Fay wrote:
> If you're working with D7 AJAX Forms, you will be interested in an API 
> change this week.
> With http://drupal.org/node/684846, the AJAX triggering was 
> refactored, and this has some effects on those of you using it:
> The bottom line: The submit function and form_set_error() actions only 
> take place when the entire form is submitted, and do not take place in 
> an AJAX triggered event (unless it's submitting the entire form).
> 1. Fields don't get errors reported against them in the context of a 
> single-element AJAX event. So for example, if you're triggering on a 
> select and there is another required field in the form, 
> form_set_error() will not report the fact that the other required 
> field is still empty.
> 2. The _submit() function is *no longer* executed during an AJAX 
> submission, only when the form itself is submitted. It's only run when 
> the whole form is submitted. If you have behavior in your module that 
> depends on this, you'll have to change this.
> I had some contrib code broken by a recent small interface change in 
> D7, and I think we should probably make announcements to this group 
> when these interface changes happen. I haven't figured out a better 
> way of notifying authors who might be affected.
> PS: There is some new documentation on AJAX forms at 
> http://drupal.org/node/684846. Your review and suggestions are welcome.
> -Randy
> -- 
> Randy Fay
> Drupal Development, troubleshooting, and debugging
> randy at randyfay.com <mailto:randy at randyfay.com>
> +1  970.462.7450

More information about the development mailing list