本文整理汇总了PHP中CRM_Core_Form::addChainSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::addChainSelect方法的具体用法?PHP CRM_Core_Form::addChainSelect怎么用?PHP CRM_Core_Form::addChainSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::addChainSelect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildQuickForm
/**
* Build the form object.
*
*
* @param CRM_Core_Form $form
* @param $proxSearch
*
* @return void
*/
public function buildQuickForm($form, $proxSearch)
{
// is proximity search required (2) or optional (1)?
$proxRequired = $proxSearch == 2 ? TRUE : FALSE;
$form->assign('proximity_search', TRUE);
$form->add('text', 'prox_street_address', ts('Street Address'), NULL, FALSE);
$form->add('text', 'prox_city', ts('City'), NULL, FALSE);
$form->add('text', 'prox_postal_code', ts('Postal Code'), NULL, FALSE);
$form->addChainSelect('prox_state_province_id', array('required' => $proxRequired));
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
$form->add('select', 'prox_country_id', ts('Country'), $country, $proxRequired);
$form->add('text', 'prox_distance', ts('Distance'), NULL, $proxRequired);
$proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
$form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, $proxRequired);
// prox_distance_unit
$form->addFormRule(array('CRM_Contact_Form_Task_ProximityCommon', 'formRule'), $form);
}
示例2: addCommonFields
/**
* Add the payment fields to the template.
*
* Generally this is the payment processor fields & the billing fields required
* for the payment processor. However, this has been complicated by adding
* pay later billing fields into this mix
*
* We now have the situation where the required fields cannot be set as required
* on the form level if they are required for the payment processor, as another
* processor might be selected and the validation will then be incorrect.
*
* However, if they are required for pay later we DO set them on the form level,
* presumably assuming they will be required whatever happens.
*
* As a side-note this seems to re-enforce the argument for making pay later
* operate as a payment processor rather than as a 'special thing on its own'.
*
* @param CRM_Core_Form $form
* Form that the payment fields are to be added to.
* @param array $paymentFields
* Fields that are to be shown on the payment form.
*/
protected static function addCommonFields(&$form, $paymentFields)
{
$requiredPaymentFields = array();
foreach ($paymentFields as $name => $field) {
if (!empty($field['cc_field'])) {
if ($field['htmlType'] == 'chainSelect') {
$form->addChainSelect($field['name'], array('required' => FALSE));
} else {
$form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], FALSE);
}
}
// This will cause the fields to be marked as required - but it is up to the payment processor to
// validate it.
$requiredPaymentFields[$field['name']] = $field['is_required'];
}
$form->assign('requiredPaymentFields', $requiredPaymentFields);
}
示例3: buildProfile
/**
* 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
//.........这里部分代码省略.........
示例4: addCommonFields
/**
* @param CRM_Core_Form $form
* @param bool $useRequired
* @param array $paymentFields
*/
protected static function addCommonFields(&$form, $useRequired, $paymentFields)
{
foreach ($paymentFields as $name => $field) {
if (!empty($field['cc_field'])) {
if ($field['htmlType'] == 'chainSelect') {
$form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required']));
} else {
$form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], $useRequired ? $field['is_required'] : FALSE);
}
}
}
}
示例5: addCommonFields
/**
* Add the payment fields to the template.
*
* Generally this is the payment processor fields & the billing fields required
* for the payment processor. However, this has been complicated by adding
* pay later billing fields into this mix
*
* We now have the situation where the required fields cannot be set as required
* on the form level if they are required for the payment processor, as another
* processor might be selected and the validation will then be incorrect.
*
* However, if they are required for pay later we DO set them on the form level,
* presumably assuming they will be required whatever happens.
*
* As a side-note this seems to re-enforce the argument for making pay later
* operate as a payment processor rather than as a 'special thing on its own'.
*
* @param CRM_Core_Form $form
* Form that the payment fields are to be added to.
* @param bool $useRequired
* Effectively this means are the fields required for pay-later - see above.
* @param array $paymentFields
* Fields that are to be shown on the payment form.
*/
protected static function addCommonFields(&$form, $useRequired, $paymentFields)
{
$requiredPaymentFields = array();
foreach ($paymentFields as $name => $field) {
if (!empty($field['cc_field'])) {
if ($field['htmlType'] == 'chainSelect') {
$form->addChainSelect($field['name'], array('required' => $useRequired && $field['is_required']));
} else {
$form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], $useRequired ? $field['is_required'] : FALSE);
}
}
// CRM-17071 We seem to be tying ourselves in knots around the addition
// of requiring billing fields for pay-later. Here we 'tell' the form the
// field is required if it is not otherwise marked as required and is
// required for the billing block.
$requiredPaymentFields[$field['name']] = !$useRequired ? $field['is_required'] : FALSE;
}
$form->assign('requiredPaymentFields', $requiredPaymentFields);
}
示例6: buildQuickForm
/**
* Build form for address input fields.
*
* @param CRM_Core_Form $form
* @param int $addressBlockCount
* The index of the address array (if multiple addresses on a page).
* @param bool $sharing
* False, if we want to skip the address sharing features.
* @param bool $inlineEdit
* True when edit used in inline edit.
*
* @return void
*
*/
public static function buildQuickForm(&$form, $addressBlockCount = NULL, $sharing = TRUE, $inlineEdit = FALSE)
{
// passing this via the session is AWFUL. we need to fix this
if (!$addressBlockCount) {
$blockId = $form->get('Address_Block_Count') ? $form->get('Address_Block_Count') : 1;
} else {
$blockId = $addressBlockCount;
}
$config = CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->applyFilter('__ALL__', 'trim');
$js = array();
if (!$inlineEdit) {
$js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL);
}
//make location type required for inline edit
$form->addSelect("address[{$blockId}][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit);
if (!$inlineEdit) {
$js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
}
$form->addElement('checkbox', "address[{$blockId}][is_primary]", ts('Primary location for this contact'), ts('Primary location for this contact'), $js);
if (!$inlineEdit) {
$js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
}
$form->addElement('checkbox', "address[{$blockId}][is_billing]", ts('Billing location for this contact'), ts('Billing location for this contact'), $js);
// hidden element to store master address id
$form->addElement('hidden', "address[{$blockId}][master_id]");
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = array('address_name' => array(ts('Address Name'), $attributes['address_name'], NULL), 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL), 'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL), 'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL), 'city' => array(ts('City'), $attributes['city'], NULL), 'postal_code' => array(ts('Zip / Postal Code'), array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')), NULL), 'postal_code_suffix' => array(ts('Postal Code Suffix'), array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'), NULL), 'country_id' => array(ts('Country'), $attributes['country_id'], 'country'), 'state_province_id' => array(ts('State/Province'), $attributes['state_province_id'], NULL), 'county_id' => array(ts('County'), $attributes['county_id'], NULL), 'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 12), NULL), 'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 12), NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL));
foreach ($elements as $name => $v) {
list($title, $attributes, $select) = $v;
$nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
if (empty($addressOptions[$nameWithoutID])) {
$continue = TRUE;
if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) {
$continue = FALSE;
}
if ($continue) {
continue;
}
}
//build normal select if country is not present in address block
if ($name == 'state_province_id' && !$addressOptions['country']) {
$select = 'stateProvince';
}
if (!$select) {
if ($name == 'state_province_id' || $name == 'county_id') {
$form->addChainSelect("address[{$blockId}][{$name}]");
} else {
if ($name == 'address_name') {
$name = 'name';
}
$form->addElement('text', "address[{$blockId}][{$name}]", $title, $attributes);
}
} else {
$form->addElement('select', "address[{$blockId}][{$name}]", $title, array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select());
}
}
$entityId = NULL;
if (!empty($form->_values['address']) && !empty($form->_values['address'][$blockId])) {
$entityId = $form->_values['address'][$blockId]['id'];
}
// CRM-11665 geocode override option
$geoCode = FALSE;
if (!empty($config->geocodeMethod)) {
$geoCode = TRUE;
$form->addElement('checkbox', "address[{$blockId}][manual_geo_code]", ts('Override automatic geocoding'));
}
$form->assign('geoCode', $geoCode);
// Process any address custom data -
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Address', $form, $entityId);
if (isset($groupTree) && is_array($groupTree)) {
// use simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $form);
// make sure custom fields are added /w element-name in the format - 'address[$blockId][custom-X]'
foreach ($groupTree as $id => $group) {
foreach ($group['fields'] as $fldId => $field) {
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
$groupTree[$id]['fields'][$fldId]['element_name'] = "address[{$blockId}][{$field['element_name']}]";
}
}
$defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $defaults);
// since we change element name for address custom data, we need to format the setdefault values
$addressDefaults = array();
//.........这里部分代码省略.........
示例7: location
/**
* @param CRM_Core_Form $form
*/
public static function location(&$form)
{
$config = CRM_Core_Config::singleton();
// Build location criteria based on _submitValues if
// available; otherwise, use $form->_formValues.
$formValues = $form->_submitValues;
if (empty($formValues) && !empty($form->_formValues)) {
$formValues = $form->_formValues;
}
$form->addElement('hidden', 'hidden_location', 1);
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = array('street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), 'city' => array(ts('City'), $attributes['city'], NULL, NULL), 'postal_code' => array(ts('Zip / Postal Code'), $attributes['postal_code'], NULL, NULL), 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), 'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE), 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL));
$parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0);
$form->assign('parseStreetAddress', $parseStreetAddress);
foreach ($elements as $name => $v) {
list($title, $attributes, $select, $multiSelect) = $v;
if (in_array($name, array('street_number', 'street_name', 'street_unit'))) {
if (!$parseStreetAddress) {
continue;
}
} elseif (!$addressOptions[$name]) {
continue;
}
if (!$attributes) {
$attributes = $attributes[$name];
}
if ($select) {
if ($select == 'stateProvince' || $select == 'county') {
$element = $form->addChainSelect($name);
} else {
$selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select();
$element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2'));
}
if ($multiSelect) {
$element->setMultiple(TRUE);
}
} else {
$form->addElement('text', $name, $title, $attributes);
}
if ($addressOptions['postal_code']) {
$attr = array('class' => 'six') + (array) CRM_Utils_Array::value('postal_code', $attributes);
$form->addElement('text', 'postal_code_low', NULL, $attr + array('placeholder' => ts('From')));
$form->addElement('text', 'postal_code_high', NULL, $attr + array('placeholder' => ts('To')));
}
}
// extend addresses with proximity search
if (!empty($config->geocodeMethod)) {
$form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six'));
$form->addElement('select', 'prox_distance_unit', NULL, array('miles' => ts('Miles'), 'kilos' => ts('Kilometers')));
$form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
}
$form->addSelect('world_region', array('entity' => 'address', 'context' => 'search'));
// select for location type
$locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array('multiple' => TRUE, 'class' => 'crm-select2', 'placeholder' => ts('Primary')));
// custom data extending addresses -
$extends = array('Address');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('addressGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$elementName = 'custom_' . $field['id'];
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $field['id'], FALSE, FALSE, TRUE);
}
}
}
}
示例8: buildForm
/**
* @param CRM_Core_Form $form
*/
public function buildForm(&$form)
{
$config = CRM_Core_Config::singleton();
$countryDefault = $config->defaultContactCountry;
$form->add('text', 'distance', ts('Distance'), NULL, TRUE);
$proxUnits = array('km' => ts('km'), 'miles' => ts('miles'));
$form->add('select', 'prox_distance_unit', ts('Units'), $proxUnits, TRUE);
$form->add('text', 'street_address', ts('Street Address'));
$form->add('text', 'city', ts('City'));
$form->add('text', 'postal_code', ts('Postal Code'));
$defaults = array();
if ($countryDefault) {
$defaults['country_id'] = $countryDefault;
}
$form->addChainSelect('state_province_id');
$country = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country();
$form->add('select', 'country_id', ts('Country'), $country, TRUE, array('class' => 'crm-select2'));
$group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::nestedGroup();
$form->addElement('select', 'group', ts('Group'), $group, array('class' => 'crm-select2 huge'));
$tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
$form->addElement('select', 'tag', ts('Tag'), $tag, array('class' => 'crm-select2 huge'));
/**
* You can define a custom title for the search form
*/
$this->setTitle('Proximity Search');
/**
* if you are using the standard template, this array tells the template what elements
* are part of the search criteria
*/
$form->assign('elements', array('distance', 'prox_distance_unit', 'street_address', 'city', 'postal_code', 'country_id', 'state_province_id', 'group', 'tag'));
}
示例9: omnipaymultiprocessor_addBillingFieldsTo46Form
/**
* Add the billing field to the payment form if required.
*
* This requires 4.6.10 or greater due to an earlier bug. 4.7 should not require this.
*
* @param CRM_Core_Form $form
*/
function omnipaymultiprocessor_addBillingFieldsTo46Form(&$form)
{
$billingDetailsFields = omnipaymultiprocessor_getBillingPersonalDetailsFields($form->_paymentProcessor);
if (!empty($billingDetailsFields)) {
if (empty($form->_paymentFields)) {
$form->_paymentFields = $billingDetailsFields;
}
$metadata = omnipaymultiprocessor_getBillingPersonalDetailsMetadata($form->_paymentProcessor);
foreach ($metadata as $name => $field) {
if (!empty($field['cc_field'])) {
if (!empty($field['cc_field'])) {
if ($field['htmlType'] == 'chainSelect') {
$form->addChainSelect($field['name'], array('required' => FALSE));
} else {
$form->add($field['htmlType'], $field['name'], $field['title'], $field['attributes'], FALSE);
}
}
}
$requiredPaymentFields[$field['name']] = $field['is_required'];
}
$form->assign('requiredPaymentFields', $requiredPaymentFields);
$form->assign('billingDetailsFields', $billingDetailsFields);
}
$form->billingFieldSets['billing_name_address-group']['fields'] = array();
}