3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Form helper class for contact name section.
21 class CRM_Contact_Form_Inline_ContactName
extends CRM_Contact_Form_Inline
{
24 * Build the form object elements.
26 public function buildQuickForm() {
27 parent
::buildQuickForm();
29 // Build contact type specific fields
30 $class = 'CRM_Contact_Form_Edit_' . $this->_contactType
;
31 $class::buildQuickForm($this, 1);
32 $this->addFormRule(['CRM_Contact_Form_Inline_ContactName', 'formRule'], $this);
36 * Global validation rules for the form.
38 * @param array $fields
39 * Posted values of the form.
40 * @param array $errors
41 * List of errors to be posted back to the form.
42 * @param CRM_Contact_Form_Inline_ContactName $form
46 public static function formRule($fields, $errors, $form) {
47 if (empty($fields['first_name']) && empty($fields['last_name'])
48 && empty($fields['organization_name'])
49 && empty($fields['household_name'])) {
50 $emails = civicrm_api3('Email', 'getcount', ['contact_id' => $form->_contactId
]);
52 $errorField = $form->_contactType
== 'Individual' ?
'last' : strtolower($form->_contactType
);
53 $errors[$errorField . '_name'] = ts('Contact with no email must have a name.');
62 public function postProcess() {
63 $params = $this->exportValues();
65 // Process / save contact info
66 $params['contact_type'] = $this->_contactType
;
67 $params['contact_id'] = $this->_contactId
;
69 if (!empty($this->_contactSubType
)) {
70 $params['contact_sub_type'] = $this->_contactSubType
;
73 CRM_Contact_BAO_Contact
::create($params);