You are here

function user_badges_badge_autocomplete_validation in User Badges 6

Same name and namespace in other branches
  1. 6.2 user_badges.module \user_badges_badge_autocomplete_validation()
  2. 7 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

5 calls to user_badges_badge_autocomplete_validation()
user_badges_change_form_submit in ./user_badges.module
Process user_badges_remove_form form submissions.
user_badges_change_form_validate in ./user_badges.module
Validate user_badges_remove_form form submissions.
user_badges_products_list_form_submit in ./user_badges_products.module
Process user_badges_products_list_form form submissions.
user_badges_products_list_form_validate in ./user_badges_products.module
Validate user_badges_products_list_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 511
@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
    if (db_result(db_query('SELECT COUNT(*) FROM {user_badges_badges} b WHERE b.bid=%d', $matches[1]))) {

      //Result found
      return array(
        $matches[1],
        'valid',
      );
    }
    else {

      //No result found, return the error code
      return array(
        $matches[1],
        'nobid',
      );
    }
  }
  else {

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