You are here

function conditional_fields_required_radios_validate in Conditional Fields 6.2

Custom validation for radio buttons. Reproduces the behavior of _form_validate, while adding an empty option.

1 string reference to 'conditional_fields_required_radios_validate'
conditional_fields_custom_required_field in ./conditional_fields.module
Unset the #required property and set a #conditional_fields_required property for custom validation.

File

./conditional_fields.module, line 1370
Content fields and groups visibility based on the values of user defined 'trigger' fields.

Code

function conditional_fields_required_radios_validate($elements) {
  $elements['#options'][''] = t('N/A');
  if (isset($elements['#options']) && isset($elements['#value'])) {
    if (is_array($elements['#value'])) {
      foreach ($elements['#value'] as $v) {
        if (!isset($elements['#options'][$v])) {
          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' => $v,
            '!name' => empty($elements['#title']) ? $elements['#parents'][0] : $elements['#title'],
          ), WATCHDOG_ERROR);
        }
      }
    }
    elseif (!isset($elements['#options'][$elements['#value']])) {
      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);
    }
  }
}