3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
35 * Form helper class for contact name section.
37 class CRM_Contact_Form_Inline_ContactName
extends CRM_Contact_Form_Inline
{
40 * Build the form object elements.
42 public function buildQuickForm() {
43 parent
::buildQuickForm();
45 // Build contact type specific fields
46 $class = 'CRM_Contact_Form_Edit_' . $this->_contactType
;
47 $class::buildQuickForm($this, 1);
48 $this->addFormRule(array('CRM_Contact_Form_Inline_ContactName', 'formRule'), $this);
52 * Global validation rules for the form.
54 * @param array $fields
55 * Posted values of the form.
56 * @param array $errors
57 * List of errors to be posted back to the form.
58 * @param CRM_Contact_Form_Inline_ContactName $form
62 public static function formRule($fields, $errors, $form) {
63 if (empty($fields['first_name']) && empty($fields['last_name'])
64 && empty($fields['organization_name'])
65 && empty($fields['household_name'])) {
66 $emails = civicrm_api3('Email', 'getcount', array('contact_id' => $form->_contactId
));
68 $errorField = $form->_contactType
== 'Individual' ?
'last' : strtolower($form->_contactType
);
69 $errors[$errorField . '_name'] = ts('Contact with no email must have a name.');
78 public function postProcess() {
79 $params = $this->exportValues();
81 // Process / save contact info
82 $params['contact_type'] = $this->_contactType
;
83 $params['contact_id'] = $this->_contactId
;
85 if (!empty($this->_contactSubType
)) {
86 $params['contact_sub_type'] = $this->_contactSubType
;
89 CRM_Contact_BAO_Contact
::create($params);