/** * add rule for household * * @params array $fields array of form values * * @return $error * @static * @public */ function formRule(&$fields) { $errors = array(); $primaryEmail = CRM_Contact_Form_Edit::formRule($fields, $errors); // make sure that household name is set if (!CRM_Utils_Array::value('household_name', $fields)) { $errors['household_name'] = 'Household Name should be set.'; } return empty($errors) ? true : $errors; }
function formRule(&$fields) { $errors = array(); $primaryEmail = CRM_Contact_Form_Edit::formRule($fields, $errors); // make sure that organization name is set if (!CRM_Utils_Array::value('organization_name', $fields)) { $errors['organization_name'] = 'Organization Name should be set.'; } // add code to make sure that the uniqueness criteria is satisfied return empty($errors) ? true : $errors; }
/** * global form rule * * @param array $fields the input form values * @param array $files the uploaded files if any * @param array $options additional user data * * @return true if no errors, else array of errors * @access public * @static */ function formRule(&$fields, &$files, $options) { $errors = array(); $primaryEmail = CRM_Contact_Form_Edit::formRule($fields, $errors); // check for state/country mapping CRM_Contact_Form_Address::formRule($fields, $errors); // make sure that firstName and lastName or a primary email is set if (!(CRM_Utils_Array::value('first_name', $fields) && CRM_Utils_Array::value('last_name', $fields) || !empty($primaryEmail))) { $errors['_qf_default'] = ts('First Name and Last Name OR an email in the Primary Location should be set.'); } // if this is a forced save, ignore find duplicate rule if (!CRM_Utils_Array::value('_qf_Edit_next_duplicate', $fields)) { $cid = null; if ($options) { $cid = (int) $options; } $ids = CRM_Core_BAO_UFGroup::findContact($fields, $cid, true); if ($ids) { $urls = array(); foreach (explode(',', $ids) as $id) { $displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $id, 'display_name'); $urls[] = '<a href="' . CRM_Utils_System::url('civicrm/contact/view', 'reset=1&action=update&cid=' . $id) . '">' . $displayName . '</a>'; } $url = implode(', ', $urls); $errors['_qf_default'] = ts('One matching contact was found. You can edit it here: %1, or click Save Duplicate Contact button below.', array(1 => $url, 'count' => count($urls), 'plural' => '%count matching contacts were found. You can edit them here: %1, or click Save Duplicate Contact button below.')); // let smarty know that there are duplicates $template =& CRM_Core_Smarty::singleton(); $template->assign('isDuplicate', 1); } else { if (CRM_Utils_Array::value('_qf_Edit_refresh_dedupe', $fields)) { // add a session message for no matching contacts CRM_Core_Session::setStatus('No matching contact found.'); } } } return empty($errors) ? true : $errors; }
/** * is there any real significant data in the hierarchical location array * * @param array $fields the hierarchical value representation of this location * * @return boolean true if data exists, false otherwise * @static * @access public */ function locationDataExists(&$fields) { foreach ($fields as $name => $value) { $skipField = false; foreach ($GLOBALS['_CRM_CONTACT_FORM_EDIT']['skipFields'] as $skip) { if (strpos("[{$skip}]", $name) !== false) { $skipField = true; break; } } if ($skipField) { continue; } if (is_array($value)) { if (CRM_Contact_Form_Edit::locationDataExists($value)) { return true; } } else { if (!empty($value)) { return true; } } } return false; }