Search code examples
drupaldrupal-7

Drupal #limit_validation_errors does not work


I am constructing a form with Drupal FAPI and is a little bit complex one. What I want to do is to put a button and add some information when the user clicks it, so I need to skip validations with that button. I'm trying to use the #limit_validation_errors property but doesn't seem to work and is executing all validations.

I've noticed that when I put the element at the root level of the form tree it does work. This is what I have:

$form['application']['education']['add_education'] = array(
    '#type' => 'submit',
    '#value' => 'Add',
    '#submit' => array('_education_submit'),
    '#limit_validation_errors' => array(),
);

The code above doesn't work, the code below works though:

$form['add_education'] = array(
    '#type' => 'submit',
    '#value' => 'Add',
    '#submit' => array('_education_submit'),
    '#limit_validation_errors' => array(),
);

Solution

  • It looks like Drupal is looking for the triggering_element using the value attribute to compare; as I have another button with the same value, the system is messing up the values and taking the other button as the clicked one.

    To fix the code, I only have had to change the #value property of the button. It was working when I changed the position on the tree because in that case Drupal took the right button.