3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
37 * form helper class for contact name section
39 class CRM_Contact_Form_Inline_ContactName
extends CRM_Contact_Form_Inline
{
42 * Build the form object elements.
46 public function buildQuickForm() {
47 parent
::buildQuickForm();
49 // Build contact type specific fields
50 $class = 'CRM_Contact_Form_Edit_' . $this->_contactType
;
51 $class::buildQuickForm($this, 1);
52 $this->addFormRule(array('CRM_Contact_Form_Inline_ContactName', 'formRule'), $this);
56 * Global validation rules for the form.
58 * @param array $fields
59 * Posted values of the form.
60 * @param array $errors
61 * List of errors to be posted back to the form.
62 * @param CRM_Contact_Form_Inline_ContactName $form
66 public static function formRule($fields, $errors, $form) {
67 if (empty($fields['first_name']) && empty($fields['last_name'])
68 && empty($fields['organization_name'])
69 && empty($fields['household_name'])) {
70 $emails = civicrm_api3('Email', 'getcount', array('contact_id' => $form->_contactId
));
72 $errorField = $form->_contactType
== 'Individual' ?
'last' : strtolower($form->_contactType
);
73 $errors[$errorField . '_name'] = ts('Contact with no email must have a name.');
84 public function postProcess() {
85 $params = $this->exportValues();
87 // Process / save contact info
88 $params['contact_type'] = $this->_contactType
;
89 $params['contact_id'] = $this->_contactId
;
91 if (!empty($this->_contactSubType
)) {
92 $params['contact_sub_type'] = $this->_contactSubType
;
95 CRM_Contact_BAO_Contact
::create($params);