You are here

function webform_invitation_code_validate in Webform Invitation 7.2

Same name and namespace in other branches
  1. 8 webform_invitation.module \webform_invitation_code_validate()
  2. 7 webform_invitation.module \webform_invitation_code_validate()
  3. 2.0.x webform_invitation.module \webform_invitation_code_validate()
1 string reference to 'webform_invitation_code_validate'
webform_invitation_form_alter in ./webform_invitation.module

File

./webform_invitation.module, line 349

Code

function webform_invitation_code_validate($form, &$form_state) {
  if (isset($form_state['values']['submitted']['webform_invitation_code'])) {
    $code = $form_state['values']['submitted']['webform_invitation_code'];
    $result = db_select('webform_invitation_codes', 'c')
      ->fields('c')
      ->condition('code', $code, '=')
      ->execute()
      ->fetchAssoc();
    if (!isset($result) || $result == NULL) {
      form_set_error('webform_invitation_code', t('This code is not valid.'));
    }
    elseif ($result['used'] > 0) {

      // Not required, handled by webform => UNIQUE option.

      #form_set_error('invitation_code', 'This code has already been used.');
    }
    else {

      // valid code, update db
      $num = db_update('webform_invitation_codes')
        ->fields(array(
        'used' => REQUEST_TIME,
      ))
        ->condition('code', $code, '=')
        ->execute();
    }
  }
}