In hope that someone else doesn't have to spend 2 hours wondering why the #limit_validation_errors property doesn't work in their form's submit button.

This happened in a multistep form that had a "Previous" button. This is what the element definition looked like:

      $this->form['actions']['prev'] = array(
        '#type' => 'submit',
        '#value' => t('< Previous'),
        '#name' => 'prev',
        '#limit_validation_errors' => array(),
      );

Supposedly, this will prevent validation of required elements when you click "Previous" (to go back to the previous step). Well, it didn't work. It still validated the empty required fields, and prevented the user from going back.

There is a hidden explanation of this issue in form.inc:

The #limit_validation_errors property is ignored if submit handlers will run, but the element doesn't have a #submit property

Basically, the #limit... will be ignored in my element above because it did not explicitly declared a #submit property (NB: the correct submit handler IS called, in this case "MY_FORM_BUILDER_submit()", but the #limit... property was ignored).

Solution (after hours of searching):

      $this->form['actions']['prev'] = array(
        '#type' => 'submit',
        '#value' => t('< Previous'),
        '#name' => 'prev',
        '#submit' => array('my_submit_handler'),
        '#limit_validation_errors' => array(),
      );

 

Accepted answer

And... like someone once told me: "1 minute spent reading the documentation will save you 1 hour of head scratching".

Alas, this IS documented in the FAPI documentation for the #limit... property. It's even in italics. Oh well...

Comments