function webform_invitation_code_validate in Webform Invitation 7
Same name and namespace in other branches
- 8 webform_invitation.module \webform_invitation_code_validate()
- 7.2 webform_invitation.module \webform_invitation_code_validate()
- 2.0.x webform_invitation.module \webform_invitation_code_validate()
1 string reference to 'webform_invitation_code_validate'
File
- ./
webform_invitation.module, line 359
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', '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();
}
}
}