You are here

function regcode_code_element_validate in Registration codes 8

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

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

1 string reference to 'regcode_code_element_validate'
regcode_form_user_register_form_alter in ./regcode.module
Implements hook_form_FORM_ID_alter() for user_register_form.

File

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

Code

function regcode_code_element_validate(array &$element, FormStateInterface $form_state) {
  $regcode = $form_state
    ->getValue('regcode');
  if (!empty($regcode)) {
    $code = regcode_code_validate($regcode);
    if (!is_object($code)) {
      $form_state
        ->setError($element, regcode_errormsg($code));
      \Drupal::logger('regcode')
        ->warning('User entered invalid registration code (@code)', [
        '@code' => $regcode,
      ]);
    }
  }
}