You are here

function conditional_fields_node_editing_form_validate in Conditional Fields 5

Same name and namespace in other branches
  1. 6 conditional_fields.module \conditional_fields_node_editing_form_validate()

Validation for node editing form.

File

./conditional_fields.module, line 582

Code

function conditional_fields_node_editing_form_validate($form_id, $form_values, $form, $data, $required_fields) {

  // If controlled required field (or required field in a controlled group) was triggered, set error
  foreach ($data as $row) {
    if ($required_fields[$row['field_name']] && conditional_fields_is_triggered($form_values[$row['control_field_name']], $row['trigger_values'])) {
      if ($required_fields[$row['field_name']]['in_group']) {
        conditional_fields_find_required_field($form[$required_fields[$row['field_name']]['in_group']][$row['field_name']], TRUE);
        _form_validate($form[$required_fields[$row['field_name']]['in_group']][$row['field_name']]);
      }
      else {
        conditional_fields_find_required_field($form[$row['field_name']], TRUE);
        _form_validate($form[$row['field_name']]);
      }
      unset($required_fields[$row['field_name']]);
    }
  }

  // This is to catch remaining fields (required fields in controlled groups)
  foreach ((array) $required_fields as $field_in_group) {
    if (!$control_field || $control_field['field_name'] != $field_in_group['in_group']) {
      $control_field = db_fetch_array(db_query("SELECT control_field_name, field_name, trigger_values FROM {conditional_fields} WHERE field_name = '%s' AND type = '%s'", $field_in_group['in_group'], $form_values['type']));
    }
    if ($control_field && conditional_fields_is_triggered($form_values[$control_field['control_field_name']], unserialize($control_field['trigger_values']))) {
      conditional_fields_find_required_field($form[$field_in_group['in_group']][$field_in_group['field']], TRUE);
      _form_validate($form[$field_in_group['in_group']][$field_in_group['field']]);
    }
  }
}