Hi,
This is a follow up on previous submit validates required radios form elements issue on the examples project.
It seems that required 'radios' form elements are validated even if '#limit_validation_errors' => array() is set on the submit button which is supposed to stop the form from being validated.

The problem seems to be happening in line 1308 of form.inc, in _form_validate():

        // Non-multiple select fields always have a value in HTML. If the user
        // does not change the form, it will be the value of the first option.
        // Because of this, form validation for the field will almost always
        // pass, even if the user did not select anything. To work around this
        // browser behavior, required select fields without a #default_value get
        // an additional, first empty option. In case the submitted value is
        // identical to the empty option's value, we reset the element's value
        // to NULL to trigger the regular #required handling below.
        // @see form_process_select()
        elseif ($elements['#type'] == 'select' && !$elements['#multiple'] && $elements['#required'] && !isset($elements['#default_value']) && $elements['#value'] === $elements['#empty_value']) {
          $elements['#value'] = NULL;
          form_set_value($elements, NULL, $form_state);
        }
        elseif (!isset($options[$elements['#value']])) { // here
          form_error($elements, $t('An illegal choice has been detected. Please contact the site administrator.'));
          watchdog('form', 'Illegal choice %choice in %name element.', array('%choice' => $elements['#value'], '%name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title']), WATCHDOG_ERROR);
        }

Probably depending on '#limit_validation_errors' value of the submit button an appropriate value must be sent to form_error function as the 3rd parameter?

Comments

iamEAP’s picture

Status: Active » Closed (works as designed)

This is expected behavior. It's the difference between #limit_validation_errors vs. #limit_validations

See: http://drupal.org/node/1488294#comment-6584924