function invite_form_validate in Invite 6.2
Same name and namespace in other branches
- 5.2 invite.module \invite_form_validate()
- 5 invite.module \invite_form_validate()
- 7.4 includes/invite.admin.inc \invite_form_validate()
- 7.2 invite.module \invite_form_validate()
Forms API callback; validate submitted form data.
Filters out e-mails that are already registered or have been invited before. Checks the invite limit of the user and the max. number of invites per turn.
File
- ./
invite.module, line 947 - Allows your users to send and track invitations to join your site.
Code
function invite_form_validate($form, &$form_state) {
global $user;
$emails = _invite_get_emails($form_state['values']['email']);
if (!$form_state['values']['resent']) {
if (count($emails) > 0) {
// Filter out already registered users, but pass validation.
$failed_emails = _invite_validate_emails("SELECT mail AS email FROM {users} WHERE mail IN (" . db_placeholders($emails, 'varchar') . ")", $emails);
if (count($failed_emails)) {
$error = format_plural(count($failed_emails), 'The following recipient is already a member:', 'The following recipients are already members:') . '<br />';
foreach ($failed_emails as $key => $email) {
$account = user_load(array(
'mail' => $email,
));
$failed_emails[$key] = theme('username', $account) . ' (' . check_plain($email) . ')';
}
$error .= implode(', ', $failed_emails);
drupal_set_message($error, 'error');
}
}
if (!empty($emails)) {
// Filter out already invited users, but pass validation.
$failed_emails = _invite_validate_emails("SELECT email FROM {invite} WHERE email IN (" . db_placeholders($emails, 'varchar') . ") AND uid = %d AND canceled = 0", $emails, $user->uid);
if (count($failed_emails)) {
$error = format_plural(count($failed_emails), 'You have already invited the following recipient:', 'You have already invited the following recipients:') . '<br />';
$error .= implode(', ', array_map('check_plain', $failed_emails));
drupal_set_message($error, 'error');
}
}
// Check that there is at least one valid e-mail remaining after filtering
// out dupes.
if (count($emails) == 0) {
form_set_error('email', t('Please enter valid e-mail addresses.'));
return;
}
// Check invite limit, fail to let the user choose which ones to send.
if (isset($form_state['values']['remaining_invites']) && count($emails) > $form_state['values']['remaining_invites']) {
form_set_error('email', format_plural($form_state['values']['remaining_invites'], 'You have only 1 invite left.', 'You have only @count invites left.'));
return;
}
// Check number of e-mails.
if (!user_access('send mass invitations') && count($emails) > 1) {
form_set_error('email', t('You cannot send more than one invitation.'));
return;
}
}
// Save valid emails.
$form_state['values']['valid_emails'] = $emails;
}