function redhen_contact_user_registration_validate in RedHen CRM 7
Same name and namespace in other branches
- 8 modules/redhen_contact/redhen_contact.module \redhen_contact_user_registration_validate()
Registration form RedHen contact validation handler.
1 string reference to 'redhen_contact_user_registration_validate'
- redhen_contact_form_user_register_form_alter in modules/
redhen_contact/ redhen_contact.module - Implements hook_form_FORM_ID_alter().
File
- modules/
redhen_contact/ redhen_contact.module, line 1252 - Module file for RedHen contacts.
Code
function redhen_contact_user_registration_validate($form, &$form_state) {
$contact_type = $form_state['redhen_contact']
->bundle();
if (empty($form_state['values']['mail'])) {
// User registration form is invalid anyway, let that validator handle it.
return;
}
$existing_contact = redhen_contact_load_by_mail($form_state['values']['mail']);
$contact = $existing_contact ? current($existing_contact) : array();
$update_existing = variable_get(REDHEN_CONTACT_REG_UPDATE, FALSE);
// We have an existing contact, but it's of a different type.
if ($existing_contact && $contact
->bundle() !== $contact_type) {
form_set_error('', t('A Contact of type %type is already associated with the email address %email.', array(
'%type' => $contact
->bundle(),
'%email' => $form_state['values']['mail'],
)));
}
// We don't want to update contacts, but found an existing match.
if ($existing_contact && !$update_existing) {
form_set_error('', t('A contact already exists with that email address.'));
}
// Existing contact is already linked to a user.
if ($existing_contact && !is_null($contact->uid) && $update_existing) {
form_set_error('mail', t('A contact with that email address is already linked to a Drupal user.'));
}
}