You are here

function notifications_field_validate_submitted in Notifications 6.4

Validate submitted field values and set the new ones as valid array of values

1 call to notifications_field_validate_submitted()
notifications_custom_fields_form_validate in notifications_custom/notifications_custom.admin.inc
Validate field values

File

includes/object.inc, line 276
Notifications object and fields

Code

function notifications_field_validate_submitted(&$form_state, $element_name = 'fields', $require_one = TRUE, $require_all = TRUE) {
  $checked_values = array();
  if ($field_values = notifications_field_parse_submitted($form_state, $element_name)) {
    foreach ($field_values as $key => $field) {
      $string_id = "{$element_name}][edit][{$key}";

      // We validate the field, type included
      if (notifications_field_valid_value($field['edit'])) {
        if (empty($field['parsed']) || !notifications_field_valid_value($field['value'], $field['type'])) {
          form_set_error($string_id, t('The value for this field is not valid.'));
          continue;
        }
      }
      elseif ($require_all) {
        form_set_error($string_id, t('You must set a value for this field.'));
        continue;
      }
      $checked_values[] = array(
        'type' => $field['type'],
        'value' => $field['value'],
      );
    }
  }
  elseif ($require_one) {
    form_set_error(NULL, t('You must set at least one field for this subscription type.'));
  }
  return $checked_values;
}