/** * process membership records * * @param array $params associated array of submitted values * * @access public * * @return bool */ private function processMembership(&$params) { $dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate'); $dates = array('join_date', 'start_date', 'end_date', 'reminder_date'); // get the price set associated with offline memebership $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name'); $this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); if (isset($params['field'])) { $customFields = array(); foreach ($params['field'] as $key => $value) { // if contact is not selected we should skip the row if (empty($params['primary_contact_id'][$key])) { continue; } $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']); // update contact information $this->updateContactInfo($value); $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1]; foreach ($dateTypes as $dateField => $dateVariable) { ${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]); } $calcDates = array(); $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate); foreach ($calcDates as $memType => $calcDate) { foreach ($dates as $d) { //first give priority to form values then calDates. $date = CRM_Utils_Array::value($d, $value); if (!$date) { $date = CRM_Utils_Array::value($d, $calcDate); } $value[$d] = CRM_Utils_Date::processDate($date); } } if (!empty($value['send_receipt'])) { $value['receipt_date'] = date('Y-m-d His'); } if (!empty($value['membership_source'])) { $value['source'] = $value['membership_source']; } unset($value['membership_source']); //Get the membership status if (!empty($value['membership_status'])) { $value['status_id'] = $value['membership_status']; unset($value['membership_status']); } if (empty($customFields)) { // membership type custom data $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE)); } //check for custom data $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $customFields, $key, 'Membership', $membershipTypeId); if (!empty($value['financial_type'])) { $value['financial_type_id'] = $value['financial_type']; } if (!empty($value['payment_instrument'])) { $value['payment_instrument_id'] = $value['payment_instrument']; } // handle soft credit if (is_array(CRM_Utils_Array::value('soft_credit_contact_id', $params)) && !empty($params['soft_credit_contact_id'][$key]) && CRM_Utils_Array::value($key, $params['soft_credit_amount'])) { $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key]; $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]); } if (!empty($value['receive_date'])) { $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE); } $params['actualBatchTotal'] += $value['total_amount']; unset($value['financial_type']); unset($value['payment_instrument']); $value['batch_id'] = $this->_batchId; $value['skipRecentView'] = TRUE; // make entry in line item for contribution $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]); $editedResults = array(); CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults); if (!empty($editedResults)) { unset($this->_priceSet['fields']); $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']]; unset($this->_priceSet['fields'][$editedResults['id']]['options']); $fid = $editedResults['id']; $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']); $editedResults = array(); CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults); $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']]; if (!empty($value['total_amount'])) { $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount']; } $fieldID = key($this->_priceSet['fields']); $value['price_' . $fieldID] = $editedResults['id']; $lineItem = array(); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]); //CRM-11529 for backoffice transactions //when financial_type_id is passed in form, update the //lineitems with the financial type selected in form if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) { foreach ($lineItem[$priceSetId] as &$values) { $values['financial_type_id'] = $value['financial_type_id']; } } $value['lineItems'] = $lineItem; $value['processPriceSet'] = TRUE; } // end of contribution related section unset($value['membership_type']); unset($value['membership_start_date']); unset($value['membership_end_date']); $value['is_renew'] = false; if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) { $this->_params = $params; $value['is_renew'] = true; $membership = CRM_Member_BAO_Membership::renewMembershipFormWrapper($value['contact_id'], $value['membership_type_id'], FALSE, $this, NULL, NULL, $value['custom']); // make contribution entry CRM_Member_BAO_Membership::recordMembershipContribution(array_merge($value, array('membership_id' => $membership->id))); } else { $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray); } //process premiums if (!empty($value['product_name'])) { if ($value['product_name'][0] > 0) { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $value['hidden_Premium'] = 1; $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]); $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => $value['contribution_id'], 'product_option' => $value['product_option'], 'quantity' => 1); CRM_Contribute_BAO_Contribution::addPremium($premiumParams); } } // end of premium //send receipt mail. if ($membership->id && !empty($value['send_receipt'])) { // add the domain email id $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail(); $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>"; $value['from_email_address'] = $domainEmail; $value['membership_id'] = $membership->id; CRM_Member_Form_Membership::emailReceipt($this, $value, $membership); } } } return TRUE; }
/** * Process membership records. * * @param array $params * Associated array of submitted values. * * * @return bool */ private function processMembership(&$params) { $dateTypes = array('join_date' => 'joinDate', 'membership_start_date' => 'startDate', 'membership_end_date' => 'endDate'); $dates = array('join_date', 'start_date', 'end_date', 'reminder_date'); // get the price set associated with offline membership $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_membership_type_amount', 'id', 'name'); $this->_priceSet = $priceSets = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId)); if (isset($params['field'])) { $customFields = array(); foreach ($params['field'] as $key => $value) { // if contact is not selected we should skip the row if (empty($params['primary_contact_id'][$key])) { continue; } $value['contact_id'] = CRM_Utils_Array::value($key, $params['primary_contact_id']); // update contact information $this->updateContactInfo($value); $membershipTypeId = $value['membership_type_id'] = $value['membership_type'][1]; foreach ($dateTypes as $dateField => $dateVariable) { ${$dateVariable} = CRM_Utils_Date::processDate($value[$dateField]); $fDate[$dateField] = CRM_Utils_Array::value($dateField, $value); } $calcDates = array(); $calcDates[$membershipTypeId] = CRM_Member_BAO_MembershipType::getDatesForMembershipType($membershipTypeId, $joinDate, $startDate, $endDate); foreach ($calcDates as $memType => $calcDate) { foreach ($dates as $d) { //first give priority to form values then calDates. $date = CRM_Utils_Array::value($d, $value); if (!$date) { $date = CRM_Utils_Array::value($d, $calcDate); } $value[$d] = CRM_Utils_Date::processDate($date); } } if (!empty($value['send_receipt'])) { $value['receipt_date'] = date('Y-m-d His'); } if (!empty($value['membership_source'])) { $value['source'] = $value['membership_source']; } unset($value['membership_source']); //Get the membership status if (!empty($value['membership_status'])) { $value['status_id'] = $value['membership_status']; unset($value['membership_status']); } if (empty($customFields)) { // membership type custom data $customFields = CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, $membershipTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Membership', FALSE, FALSE, NULL, NULL, TRUE)); } //check for custom data $value['custom'] = CRM_Core_BAO_CustomField::postProcess($params['field'][$key], $key, 'Membership', $membershipTypeId); if (!empty($value['financial_type'])) { $value['financial_type_id'] = $value['financial_type']; } if (!empty($value['payment_instrument'])) { $value['payment_instrument_id'] = $value['payment_instrument']; } // handle soft credit if (!empty($params['soft_credit_contact_id'][$key]) && !empty($params['soft_credit_amount'][$key])) { $value['soft_credit'][$key]['contact_id'] = $params['soft_credit_contact_id'][$key]; $value['soft_credit'][$key]['amount'] = CRM_Utils_Rule::cleanMoney($params['soft_credit_amount'][$key]); //CRM-15350: if soft-credit-type profile field is disabled or removed then //we choose Gift as default value as per Gift Membership rule if (!empty($params['soft_credit_type'][$key])) { $value['soft_credit'][$key]['soft_credit_type_id'] = $params['soft_credit_type'][$key]; } else { $value['soft_credit'][$key]['soft_credit_type_id'] = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name'); } } if (!empty($value['receive_date'])) { $value['receive_date'] = CRM_Utils_Date::processDate($value['receive_date'], $value['receive_date_time'], TRUE); } $params['actualBatchTotal'] += $value['total_amount']; unset($value['financial_type']); unset($value['payment_instrument']); $value['batch_id'] = $this->_batchId; $value['skipRecentView'] = TRUE; // make entry in line item for contribution $editedFieldParams = array('price_set_id' => $priceSetId, 'name' => $value['membership_type'][0]); $editedResults = array(); CRM_Price_BAO_PriceField::retrieve($editedFieldParams, $editedResults); if (!empty($editedResults)) { unset($this->_priceSet['fields']); $this->_priceSet['fields'][$editedResults['id']] = $priceSets['fields'][$editedResults['id']]; unset($this->_priceSet['fields'][$editedResults['id']]['options']); $fid = $editedResults['id']; $editedFieldParams = array('price_field_id' => $editedResults['id'], 'membership_type_id' => $value['membership_type_id']); $editedResults = array(); CRM_Price_BAO_PriceFieldValue::retrieve($editedFieldParams, $editedResults); $this->_priceSet['fields'][$fid]['options'][$editedResults['id']] = $priceSets['fields'][$fid]['options'][$editedResults['id']]; if (!empty($value['total_amount'])) { $this->_priceSet['fields'][$fid]['options'][$editedResults['id']]['amount'] = $value['total_amount']; } $fieldID = key($this->_priceSet['fields']); $value['price_' . $fieldID] = $editedResults['id']; $lineItem = array(); CRM_Price_BAO_PriceSet::processAmount($this->_priceSet['fields'], $value, $lineItem[$priceSetId]); //CRM-11529 for backoffice transactions //when financial_type_id is passed in form, update the //lineitems with the financial type selected in form if (!empty($value['financial_type_id']) && !empty($lineItem[$priceSetId])) { foreach ($lineItem[$priceSetId] as &$values) { $values['financial_type_id'] = $value['financial_type_id']; } } $value['lineItems'] = $lineItem; $value['processPriceSet'] = TRUE; } // end of contribution related section unset($value['membership_type']); unset($value['membership_start_date']); unset($value['membership_end_date']); $value['is_renew'] = FALSE; if (!empty($params['member_option']) && CRM_Utils_Array::value($key, $params['member_option']) == 2) { // The following parameter setting may be obsolete. $this->_params = $params; $value['is_renew'] = TRUE; $isPayLater = CRM_Utils_Array::value('is_pay_later', $params); $campaignId = NULL; if (isset($this->_values) && is_array($this->_values) && !empty($this->_values)) { $campaignId = CRM_Utils_Array::value('campaign_id', $this->_params); if (!array_key_exists('campaign_id', $this->_params)) { $campaignId = CRM_Utils_Array::value('campaign_id', $this->_values); } } foreach (array('join_date', 'start_date', 'end_date') as $dateType) { //CRM-18000 - ignore $dateType if its not explicitly passed if (!empty($fDate[$dateType]) || !empty($fDate['membership_' . $dateType])) { $formDates[$dateType] = CRM_Utils_Array::value($dateType, $value); } } $membershipSource = CRM_Utils_Array::value('source', $value); list($membership) = CRM_Member_BAO_Membership::renewMembership($value['contact_id'], $value['membership_type_id'], FALSE, NULL, NULL, $value['custom'], 1, NULL, FALSE, NULL, $membershipSource, $isPayLater, $campaignId, $formDates); // make contribution entry $contrbutionParams = array_merge($value, array('membership_id' => $membership->id)); // @todo - calling this from here is pretty hacky since it is called from membership.create anyway // This form should set the correct params & not call this fn directly. CRM_Member_BAO_Membership::recordMembershipContribution($contrbutionParams); } else { $membership = CRM_Member_BAO_Membership::create($value, CRM_Core_DAO::$_nullArray); } //process premiums if (!empty($value['product_name'])) { if ($value['product_name'][0] > 0) { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $value['hidden_Premium'] = 1; $value['product_option'] = CRM_Utils_Array::value($value['product_name'][1], $options[$value['product_name'][0]]); $premiumParams = array('product_id' => $value['product_name'][0], 'contribution_id' => CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id'), 'product_option' => $value['product_option'], 'quantity' => 1); CRM_Contribute_BAO_Contribution::addPremium($premiumParams); } } // end of premium //send receipt mail. if ($membership->id && !empty($value['send_receipt'])) { // add the domain email id $domainEmail = CRM_Core_BAO_Domain::getNameAndEmail(); $domainEmail = "{$domainEmail['0']} <{$domainEmail['1']}>"; $value['from_email_address'] = $domainEmail; $value['membership_id'] = $membership->id; $value['contribution_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipPayment', $membership->id, 'contribution_id', 'membership_id'); CRM_Member_Form_Membership::emailReceipt($this, $value, $membership); } } } return TRUE; }
/** * Add profile field to a form. * * @param CRM_Core_Form $form * @param array $field * Properties. * @param int $mode * Profile mode. * @param int $contactId * @param bool $online * @param string $usedFor * For building up prefixed fieldname for special cases (e.g. onBehalf, Honor). * @param int $rowNumber * @param string $prefix * * @return null */ public static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $usedFor = NULL, $rowNumber = NULL, $prefix = '') { $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return NULL; } if ($usedFor == 'onbehalf') { $name = "onbehalf[{$fieldName}]"; } elseif ($usedFor == 'honor') { $name = "honor[{$fieldName}]"; } elseif ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } elseif ($rowNumber) { $name = "field[{$rowNumber}][{$fieldName}]"; } elseif (!empty($prefix)) { $name = $prefix . "[{$fieldName}]"; } else { $name = $fieldName; } $selectAttributes = array('class' => 'crm-select2', 'placeholder' => TRUE); if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = json_encode(ts('Are you sure you want to delete contact image.')); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "' . htmlspecialchars("if (confirm({$deleteExtra})) this.href+='&confirmed=1'; else return false;") . '"')); $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid')), ts('more'), FALSE, 'contact.profileimage.delete', 'Contact', $form->get('id')); $form->assign('deleteURL', $deleteURL); } $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (substr($fieldName, 0, 14) === 'state_province') { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactStateProvince) { $defaultValues[$name] = $config->defaultContactStateProvince; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required, $selectAttributes); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { $form->add('file', $name, $title, $attributes, $required); $form->addUploadElement($name); } elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { if ($usedFor) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } else { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required); } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . '-provider_id'); } } } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'activityDate')); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); $sel =& $form->addElement('hierselect', $name, $title); $select = array('' => ts('- select -')); if (count($orgInfo) == 1 && $field['is_required']) { // we only have one org - so we should default to it. Not sure about defaulting to first type // as it could be missed - so adding a select // however, possibly that is more similar to the membership form if (count($types[1]) > 1) { $types[1] = $select + $types[1]; } } else { $orgInfo = $select + $orgInfo; } $sel->setOptions(array($orgInfo, $types)); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required); } elseif (in_array($fieldName, array('gender_id', 'communication_style_id'))) { $options = array(); $pseudoValues = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $fieldName); foreach ($pseudoValues as $key => $var) { $options[$key] = $form->createElement('radio', NULL, ts($title), $var, $key); } $group = $form->addGroup($options, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } else { $group->setAttribute('allowClear', TRUE); } } elseif ($fieldName === 'prefix_id' || $fieldName === 'suffix_id') { $form->addSelect($name, array('label' => $title, 'entity' => 'contact', 'field' => $fieldName, 'class' => 'six', 'placeholder' => ''), $required); } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); if ($usedFor == 'onbehalf') { $profileType = 'Organization'; } elseif ($usedFor == 'honor') { $profileType = CRM_Core_BAO_UFField::getProfileType($form->_params['honoree_profile_id']); } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; if ($profileType == 'Contact') { $profileType = 'Individual'; } } $setSubtype = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = $subtypes; } $form->add('select', $name, $title, $subtypeList, $required, array('class' => 'crm-select2', 'multiple' => TRUE)); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE); } elseif ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method'); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } elseif ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } elseif ($fieldName === 'preferred_language') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contact_BAO_Contact::buildOptions('preferred_language')); } elseif ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } elseif ($fieldName === 'group') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name); } elseif ($fieldName === 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name); } elseif (substr($fieldName, 0, 4) === 'url-') { $form->add('text', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), $required); $form->addRule($name, ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url'); } elseif (substr($fieldName, -4) == 'note') { $form->add('textarea', $name, $title, $attributes, $required); } elseif (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (substr($fieldName, 0, 14) === 'address_custom') { list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2); $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8)); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } elseif ($fieldName == 'soft_credit') { $form->addEntityRef("soft_credit_contact_id[{$rowNumber}]", ts('Soft Credit To'), array('create' => TRUE)); $form->addMoney("soft_credit_amount[{$rowNumber}]", ts('Amount'), FALSE, NULL, FALSE); } elseif ($fieldName == 'product_name') { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $sel =& $form->addElement('hierselect', $name, $title); $products = array('0' => ts('- select -')) + $products; $sel->setOptions(array($products, $options)); } elseif ($fieldName == 'payment_instrument') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } elseif ($fieldName == 'financial_type') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType(), $required); } elseif ($fieldName == 'contribution_status_id') { $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(); $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); foreach (array('In Progress', 'Overdue', 'Refunded') as $suppress) { unset($contributionStatuses[CRM_Utils_Array::key($suppress, $statusName)]); } $form->add('select', $name, $title, array('' => ts('- select -')) + $contributionStatuses, $required); } elseif ($fieldName == 'soft_credit_type') { $name = "soft_credit_type[{$rowNumber}]"; $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_OptionGroup::values("soft_credit_type")); //CRM-15350: choose SCT field default value as 'Gift' for membership use //else (for contribution), use configured SCT default value $SCTDefaultValue = CRM_Core_OptionGroup::getDefaultValue("soft_credit_type"); if ($field['field_type'] == 'Membership') { $SCTDefaultValue = CRM_Core_OptionGroup::getValue('soft_credit_type', 'Gift', 'name'); } $form->addElement('hidden', 'sct_default_id', $SCTDefaultValue, array('id' => 'sct_default_id')); } elseif ($fieldName == 'currency') { $form->addCurrency($name, $title, $required); } elseif ($fieldName == 'contribution_page_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'); } elseif ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required); } elseif ($fieldName == 'activity_engagement_level') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required); } elseif ($fieldName == 'activity_date_time') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { $cond = 'visibility_id = 1'; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required); } elseif ($fieldName == 'participant_role') { if (!empty($field['is_multiple'])) { $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE); } else { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } } elseif ($fieldName == 'world_region') { $form->add('select', $name, $title, CRM_Core_PseudoConstant::worldRegion(), $required, $selectAttributes); } elseif ($fieldName == 'signature_html') { $form->add('wysiwyg', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif ($fieldName == 'signature_text') { $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns)); $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="crm-select2 big"'); } } elseif ($fieldName == 'activity_details') { $form->add('wysiwyg', $fieldName, $title, array('rows' => 4, 'cols' => 60), $required); } elseif ($fieldName == 'activity_duration') { $form->add('text', $name, $title, $attributes, $required); $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); } else { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } static $hiddenSubtype = FALSE; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. if ($usedFor) { $form->addElement('hidden', $usedFor . '[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); } $hiddenSubtype = TRUE; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }
/** * Function to build profile form * * @params object $form form object * @params array $field array field properties * @params int $mode profile mode * @params int $contactID contact id * * @return null * @static * @access public */ static function buildProfile(&$form, &$field, $mode, $contactId = NULL, $online = FALSE, $onBehalf = FALSE, $rowNumber = NULL, $prefix = '') { $defaultValues = array(); $fieldName = $field['name']; $title = $field['title']; $attributes = $field['attributes']; $rule = $field['rule']; $view = $field['is_view']; $required = $mode == CRM_Profile_Form::MODE_SEARCH ? FALSE : $field['is_required']; $search = $mode == CRM_Profile_Form::MODE_SEARCH ? TRUE : FALSE; $isShared = CRM_Utils_Array::value('is_shared', $field, 0); // do not display view fields in drupal registration form // CRM-4632 if ($view && $mode == CRM_Profile_Form::MODE_REGISTER) { return; } if ($onBehalf) { $name = "onbehalf[{$fieldName}]"; } elseif ($contactId && !$online) { $name = "field[{$contactId}][{$fieldName}]"; } elseif ($rowNumber) { $name = "field[{$rowNumber}][{$fieldName}]"; } elseif (!empty($prefix)) { $name = $prefix . "[{$fieldName}]"; } else { $name = $fieldName; } if ($fieldName == 'image_URL' && $mode == CRM_Profile_Form::MODE_EDIT) { $deleteExtra = ts('Are you sure you want to delete contact image.'); $deleteURL = array(CRM_Core_Action::DELETE => array('name' => ts('Delete Contact Image'), 'url' => 'civicrm/contact/image', 'qs' => 'reset=1&id=%%id%%&gid=%%gid%%&action=delete', 'extra' => 'onclick = "if (confirm( \'' . $deleteExtra . '\' ) ) this.href+=\'&confirmed=1\'; else return false;"')); $deleteURL = CRM_Core_Action::formLink($deleteURL, CRM_Core_Action::DELETE, array('id' => $form->get('id'), 'gid' => $form->get('gid'))); $form->assign('deleteURL', $deleteURL); } $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (substr($fieldName, 0, 14) === 'state_province') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(), $required); } elseif (substr($fieldName, 0, 7) === 'country') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $required); $config = CRM_Core_Config::singleton(); if (!in_array($mode, array(CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH)) && $config->defaultContactCountry) { $defaultValues[$name] = $config->defaultContactCountry; $form->setDefaults($defaultValues); } } elseif (substr($fieldName, 0, 6) === 'county') { if ($addressOptions['county']) { $form->add('select', $name, $title, array('' => ts('- select state -')), $required); } } elseif (substr($fieldName, 0, 9) === 'image_URL') { $form->add('file', $name, $title, $attributes, $required); $form->addUploadElement($name); } elseif (substr($fieldName, 0, 2) === 'im') { $form->add('text', $name, $title, $attributes, $required); if (!$contactId) { if ($onBehalf) { if (substr($name, -1) == ']') { $providerName = substr($name, 0, -1) . '-provider_id]'; } $form->add('select', $providerName, NULL, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); } else { $form->add('select', $name . '-provider_id', $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::IMProvider(), $required); } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH) { $form->freeze($name . '-provider_id'); } } } elseif ($fieldName === 'birth_date' || $fieldName === 'deceased_date') { $form->addDate($name, $title, $required, array('formatType' => 'birth')); } elseif (in_array($fieldName, array('membership_start_date', 'membership_end_date', 'join_date'))) { $form->addDate($name, $title, $required, array('formatType' => 'custom')); } elseif ($field['name'] == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); $sel =& $form->addElement('hierselect', $name, $title); $select = array('' => ts('- select -')); $sel->setOptions(array($select + $orgInfo, $types)); } elseif ($field['name'] == 'membership_status') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required); } elseif ($fieldName === 'gender') { $genderOptions = array(); $gender = CRM_Core_PseudoConstant::gender(); foreach ($gender as $key => $var) { $genderOptions[$key] = $form->createElement('radio', NULL, ts('Gender'), $var, $key); } $form->addGroup($genderOptions, $name, $title); if ($required) { $form->addRule($name, ts('%1 is a required field.', array(1 => $title)), 'required'); } } elseif ($fieldName === 'individual_prefix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualPrefix(), $required); } elseif ($fieldName === 'individual_suffix') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::individualSuffix(), $required); } elseif ($fieldName === 'contact_sub_type') { $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $form->_fields[$fieldName]); if ($onBehalf) { $profileType = 'Organization'; } else { $profileType = $gId ? CRM_Core_BAO_UFField::getProfileType($gId) : NULL; } $setSubtype = FALSE; if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $setSubtype = $profileType; $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $subtypes = $profileType ? CRM_Contact_BAO_ContactType::subTypePairs($profileType) : array(); if ($setSubtype) { $subtypeList = array(); $subtypeList[$setSubtype] = $subtypes[$setSubtype]; } else { $subtypeList = $subtypes; } $sel = $form->add('select', $name, $title, $subtypeList, $required); $sel->setMultiple(TRUE); } elseif (in_array($fieldName, CRM_Contact_BAO_Contact::$_greetingTypes)) { //add email greeting, postal greeting, addressee, CRM-4575 $gId = $form->get('gid') ? $form->get('gid') : CRM_Utils_Array::value('group_id', $field); $profileType = CRM_Core_BAO_UFField::getProfileType($gId, TRUE, FALSE, TRUE); if (empty($profileType) || in_array($profileType, array('Contact', 'Contribution', 'Participant', 'Membership'))) { $profileType = 'Individual'; } if (CRM_Contact_BAO_ContactType::isaSubType($profileType)) { $profileType = CRM_Contact_BAO_ContactType::getBasicType($profileType); } $greeting = array('contact_type' => $profileType, 'greeting_type' => $fieldName); $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::greeting($greeting), $required); // add custom greeting element $form->add('text', $fieldName . '_custom', ts('Custom %1', array(1 => ucwords(str_replace('_', ' ', $fieldName)))), NULL, FALSE); } elseif ($fieldName === 'preferred_communication_method') { $communicationFields = CRM_Core_PseudoConstant::pcm(); foreach ($communicationFields as $key => $var) { if ($key == '') { continue; } $communicationOptions[] = $form->createElement('checkbox', $key, NULL, $var); } $form->addGroup($communicationOptions, $name, $title, '<br/>'); } elseif ($fieldName === 'preferred_mail_format') { $form->add('select', $name, $title, CRM_Core_SelectValues::pmf()); } elseif ($fieldName === 'preferred_language') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::languages()); } elseif ($fieldName == 'external_identifier') { $form->add('text', $name, $title, $attributes, $required); $contID = $contactId; if (!$contID) { $contID = $form->get('id'); } $form->addRule($name, ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $contID, 'external_identifier')); } elseif ($fieldName === 'group') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, TRUE, $required, $title, NULL, $name); } elseif ($fieldName === 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId, CRM_Contact_Form_Edit_TagsAndGroups::TAG, FALSE, $required, NULL, $title, $name); } elseif (substr($fieldName, 0, 4) === 'url-') { $form->addElement('text', $name, $title, array_merge(CRM_Core_DAO::getAttribute('CRM_Core_DAO_Website', 'url'), array('onfocus' => "if (!this.value) { this.value='http://';} else return false", 'onblur' => "if ( this.value == 'http://') { this.value='';} else return false"))); $form->addRule($name, ts('Enter a valid Website.'), 'url'); //Website type select if ($onBehalf) { if (substr($name, -1) == ']') { $websiteTypeName = substr($name, 0, -1) . '-website_type_id]'; } $form->addElement('select', $websiteTypeName, NULL, CRM_Core_PseudoConstant::websiteType()); } else { $form->addElement('select', $name . '-website_type_id', NULL, CRM_Core_PseudoConstant::websiteType()); } // added because note appeared as a standard text input } elseif ($fieldName == 'note') { $form->add('textarea', $name, $title, $attributes, $required); } elseif (substr($fieldName, 0, 6) === 'custom') { $customFieldID = CRM_Core_BAO_CustomField::getKeyID($fieldName); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (substr($fieldName, 0, 14) === 'address_custom') { list($fName, $locTypeId) = CRM_Utils_System::explode('-', $fieldName, 2); $customFieldID = CRM_Core_BAO_CustomField::getKeyID(substr($fName, 8)); if ($customFieldID) { CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, FALSE, $required, $search, $title); } } elseif (in_array($fieldName, array('receive_date', 'receipt_date', 'thankyou_date', 'cancel_date'))) { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } elseif ($fieldName == 'soft_credit') { CRM_Contact_Form_NewContact::buildQuickForm($form, $rowNumber, NULL, FALSE, 'soft_credit_'); } elseif ($fieldName == 'product_name') { list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo(); $sel =& $form->addElement('hierselect', $name, $title); $products = array('0' => ts('- select -')) + $products; $sel->setOptions(array($products, $options)); } elseif ($fieldName == 'payment_instrument') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), $required); } elseif ($fieldName == 'contribution_type') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionType(), $required); } elseif ($fieldName == 'contribution_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionStatus(), $required); } elseif ($fieldName == 'currency') { $form->addCurrency($name, $title, $required); } elseif ($fieldName == 'contribution_page_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'); } elseif ($fieldName == 'participant_register_date') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::activityStatus(), $required); } elseif ($fieldName == 'activity_engagement_level') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Campaign_PseudoConstant::engagementLevel(), $required); } elseif ($fieldName == 'activity_date_time') { $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { $cond = 'visibility_id = 1'; } $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required); } elseif ($fieldName == 'participant_role') { if (CRM_Utils_Array::value('is_multiple', $field)) { $form->addCheckBox($name, $title, CRM_Event_PseudoConstant::participantRole(), NULL, NULL, NULL, NULL, ' ', TRUE); } else { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), $required); } } elseif ($fieldName == 'scholarship_type_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('scholarship_type', TRUE))); } elseif ($fieldName == 'applicant_status_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + array_flip(CRM_Core_OptionGroup::values('applicant_status', TRUE))); } elseif ($fieldName == 'highschool_gpa_id') { $form->add('select', $name, $title, array('' => '-- Select -- ') + CRM_Core_OptionGroup::values('highschool_gpa')); } elseif ($fieldName == 'world_region') { $form->add('select', $name, $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::worldRegion(), $required); } elseif ($fieldName == 'signature_html') { $form->addWysiwyg($name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif ($fieldName == 'signature_text') { $form->add('textarea', $name, $title, CRM_Core_DAO::getAttribute('CRM_Core_DAO_Email', $fieldName)); } elseif (substr($fieldName, -11) == 'campaign_id') { if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(CRM_Utils_Array::value($contactId, $form->_componentCampaigns)); $campaign =& $form->add('select', $name, $title, array('' => ts('- select -')) + $campaigns, $required, 'class="big"'); } } elseif ($fieldName == 'activity_details') { $form->addWysiwyg($fieldName, $title, array('rows' => 4, 'cols' => 60), $required); } elseif ($fieldName == 'activity_duration') { $form->add('text', $fieldName, $title, $attributes, $required); $form->addRule($name, ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); } else { $processed = FALSE; if (CRM_Core_Permission::access('Quest', FALSE)) { $processed = CRM_Quest_BAO_Student::buildStudentForm($form, $fieldName, $title, $contactId); } if (!$processed) { if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } else { $form->add('text', $name, $title, $attributes, $required); } } } static $hiddenSubtype = FALSE; if (!$hiddenSubtype && CRM_Contact_BAO_ContactType::isaSubType($field['field_type'])) { // In registration mode params are submitted via POST and we don't have any clue // about profile-id or the profile-type (which could be a subtype) // To generalize the behavior and simplify the process, // lets always add the hidden //subtype value if there is any, and we won't have to // compute it while processing. if ($onBehalf) { $form->addElement('hidden', 'onbehalf[contact_sub_type]', $field['field_type']); } else { $form->addElement('hidden', 'contact_sub_type_hidden', $field['field_type']); } $hiddenSubtype = TRUE; } if ($view && $mode != CRM_Profile_Form::MODE_SEARCH || $isShared) { $form->freeze($name); } //add the rules if (in_array($fieldName, array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount'))) { $form->addRule($name, ts('Please enter a valid amount.'), 'money'); } if ($rule) { if (!($rule == 'email' && $mode == CRM_Profile_Form::MODE_SEARCH)) { $form->addRule($name, ts('Please enter a valid %1', array(1 => $title)), $rule); } } }