function redhen_contact_contact_form_validate in RedHen CRM 7
Validation callback for redhen_contact_contact_form().
1 string reference to 'redhen_contact_contact_form_validate'
- redhen_contact_contact_form in modules/
redhen_contact/ includes/ redhen_contact.forms.inc - Form callback: create or edit a contact.
File
- modules/
redhen_contact/ includes/ redhen_contact.forms.inc, line 92 - Forms for creating, editing, and deleting contacts.
Code
function redhen_contact_contact_form_validate($form, &$form_state) {
$contact = $form_state['redhen_contact'];
// Notify field widgets to validate their data.
field_attach_form_validate('redhen_contact', $contact, $form, $form_state);
// If mirroring a connected and contact email's, ensure the email is not used
// by another Drupal user.
if (redhen_contact_user_email_setting(REDHEN_CONTACT_MIRROR_EMAIL, $contact) && $contact->uid) {
foreach ($form_state['values'][REDHEN_CONTACT_EMAIL_FIELD][LANGUAGE_NONE] as $email) {
if (is_array($email) && !empty($email['value']) && $email['default']) {
$user = user_load_by_mail($email['value']);
if ($user && $user->uid != $contact->uid) {
form_set_error(REDHEN_CONTACT_EMAIL_FIELD, t("This contact's primary email is configured to mirror the associated Drupal user and email address %email is already in use by another Drupal user.", array(
'%email' => $email['value'],
)));
break;
}
}
}
}
}