You are here

function user_badges_roles_form_validate in User Badges 7

Same name and namespace in other branches
  1. 6.2 user_badges.admin.inc \user_badges_roles_form_validate()
  2. 6 user_badges.admin.inc \user_badges_roles_form_validate()
  3. 7.4 includes/user_badges.admin.inc \user_badges_roles_form_validate()
  4. 7.2 user_badges.admin.inc \user_badges_roles_form_validate()
  5. 7.3 user_badges.admin.inc \user_badges_roles_form_validate()

Validation function for user_badges_roles_form.

File

./user_badges.admin.inc, line 657
@brief User Badges admin functions

Code

function user_badges_roles_form_validate($form, &$form_state) {
  $array = $form_state['values']['roles'] + $form_state['values']['blocked'];

  // Go through all the entries and make sure they all have a valid badge ID.
  foreach ($array as $field => $value) {
    if (!empty($value)) {

      // The field isn't empty, so we should validate it.
      $validation = user_badges_badge_autocomplete_validation($value);

      //Is it correctly formatted?
      if ($validation[1] == 'string') {
        if ($field == 0) {
          form_set_error('blocked][' . $field, t('"@value" is not a valid badge name. Try using the autocomplete function (requires javascript).', array(
            '@value' => $value,
          )));
        }
        else {
          form_set_error('roles][' . $field, t('"@value" is not a valid badge name. Try using the autocomplete function (requires javascript).', array(
            '@value' => $value,
          )));
        }
      }
      elseif ($validation[1] == 'nobid') {
        if ($field == 0) {
          form_set_error('blocked][' . $field, t('@value is not a valid badge ID. Try using the autocomplete function (requires javascript).', array(
            '@value' => $validation[0],
          )));
        }
        else {
          form_set_error('roles][' . $field, t('@value is not a valid badge ID. Try using the autocomplete function (requires javascript).', array(
            '@value' => $validation[0],
          )));
        }
      }
    }
  }
}