You are here

function user_badges_badge_autocomplete_validation in User Badges 7

Same name and namespace in other branches
  1. 6.2 user_badges.module \user_badges_badge_autocomplete_validation()
  2. 6 user_badges.module \user_badges_badge_autocomplete_validation()
  3. 7.2 user_badges.module \user_badges_badge_autocomplete_validation()
  4. 7.3 user_badges.module \user_badges_badge_autocomplete_validation()

Validates submissions for textfields that use user_badges_badge_autocomplete strings

Parameters

$value: The textfield value

Return value

array($bid,$result) $bid the bid detected in the string (integer) for an invalid string, this will be NULL $result 'valid' for a valid string with a real bid 'string' for an incorrectly formatted string 'nobid' for a correctly formatted string with an invalid badge ID

3 calls to user_badges_badge_autocomplete_validation()
user_badges_change_form_submit in ./user_badges.module
Process user_badges_change_form form submissions.
user_badges_change_form_validate in ./user_badges.module
Validate user_badges_remove_form form submissions.
user_badges_roles_form_validate in ./user_badges.admin.inc
Validation function for user_badges_roles_form.

File

./user_badges.module, line 617
@brief User Badges module file

Code

function user_badges_badge_autocomplete_validation($value) {
  if (preg_match('/\\(' . t('Badge ID') . ' (\\d+)\\)/', $value, $matches)) {

    //The format was correct, but we need to check the bid exists
    $bid = $matches[1];
    $records = db_select('user_badges_badges', 'ubb')
      ->fields('ubb')
      ->condition('ubb.bid', $bid)
      ->execute();
    if ($records
      ->rowCount() > 0) {

      //Result found
      return array(
        $bid,
        'valid',
      );
    }
    else {

      //No result found, return the error code
      return array(
        $bid,
        'nobid',
      );
    }
  }
  else {

    //Pattern does not match, return the error code
    return array(
      NULL,
      'string',
    );
  }
}