You are here

function regcode_code_element_validate in Registration codes 7.2

Same name and namespace in other branches
  1. 8 regcode.module \regcode_code_element_validate()
  2. 7 regcode.module \regcode_code_element_validate()

Validate the content of the code-field on user registration.

3 string references to 'regcode_code_element_validate'
regcode_form_user_register_form_alter in ./regcode.module
Implements hook_form_FORM_ID_alter().
regcode_menu in ./regcode.module
Implements hook_menu().
regcode_voucher_form_user_profile_form_alter in regcode_voucher/regcode_voucher.module
Implements hook_form_FORM_ID_alter().

File

./regcode.module, line 195
Main functionality and hooks of regcode module.

Code

function regcode_code_element_validate(&$element, &$form_state) {

  // ajax_call is for detecting ajax call.
  if ($_POST['ajax_call'] == 1) {
    $element['#value'] = $_POST['code'];
    $error = array();
    $error['validated'] = TRUE;
  }
  if (!empty($element['#value'])) {
    $code = regcode_code_validate($element['#value']);
    if (!is_object($code)) {
      if ($_POST['ajax_call'] == 1) {
        $error['msgtxt'] = regcode_errormsg($code);
        $error['validated'] = FALSE;
      }
      else {
        form_error($element, regcode_errormsg($code));
      }
      watchdog('regcode', 'User entered invalid registration code (@code)', array(
        '@code' => $element['#value'],
      ), WATCHDOG_WARNING);
    }
  }
  if (!empty($error)) {
    print json_encode($error);
    exit;
  }
}