Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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(),
);
like image 529
Daniel Salazar Avatar asked Mar 24 '26 09:03

Daniel Salazar


2 Answers

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.

like image 72
Daniel Salazar Avatar answered Mar 27 '26 09:03

Daniel Salazar


Here is the example of using this property:

$form['add_education'] = array(
    '#type' => 'submit',
    '#value' => 'Add',
    '#submit' => array('submit_function'),
    '#limit_validation_errors' => array(array('_education_submit')),
);
like image 26
Computrance Avatar answered Mar 27 '26 07:03

Computrance