本文整理汇总了PHP中CRM_Core_Form::addField方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::addField方法的具体用法?PHP CRM_Core_Form::addField怎么用?PHP CRM_Core_Form::addField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::addField方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildQuickForm
/**
* Build the form object elements for Demographics object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
*/
public static function buildQuickForm(&$form)
{
$form->addField('gender_id', array('entity' => 'contact', 'type' => 'Radio', 'allowClear' => TRUE));
$form->addField('birth_date', array('entity' => 'contact', 'formatType' => 'birth'));
$form->addField('is_deceased', array('entity' => 'contact', 'label' => ts('Contact is Deceased'), 'onclick' => "showDeceasedDate()"));
$form->addField('deceased_date', array('entity' => 'contact', 'formatType' => 'birth'));
}
示例2: buildQuickForm
/**
* This function provides the HTML form elements that are specific to the Individual Contact Type.
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL)
{
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
$nameFields = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_edit_options', TRUE, NULL, FALSE, 'name', TRUE, 'AND v.filter = 2');
// Use names instead of labels to build form.
$nameFields = array_keys($nameFields);
// Fixme: dear god why? these come out in a format that is NOT the name of the fields.
foreach ($nameFields as &$fix) {
$fix = str_replace(' ', '_', strtolower($fix));
if ($fix == 'prefix' || $fix == 'suffix') {
// God, why god?
$fix .= '_id';
}
}
foreach ($nameFields as $name) {
$props = array();
if ($name == 'prefix_id' || $name == 'suffix_id') {
$options = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $name);
// Skip if we have no options available
if (!CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', $name)) {
//continue;
}
$props = array('class' => 'eight', 'placeholder' => ' ', 'label' => $name == 'prefix_id' ? ts('Prefix') : ts('Suffix'));
}
$form->addField($name, $props);
}
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addField('nick_name');
// job title
// override the size for UI to look better
$form->addField('job_title', array('size' => '30'));
//Current Employer Element
$props = array('api' => array('params' => array('contact_type' => 'Organization')), 'create' => TRUE);
$form->addField('employer_id', $props);
$form->addField('contact_source', array('class' => 'big'));
}
if (!$inlineEditMode) {
$checkSimilar = Civi::settings()->get('contact_ajax_check_similar');
if ($checkSimilar == NULL) {
$checkSimilar = 0;
}
$form->assign('checkSimilar', $checkSimilar);
//External Identifier Element
$form->addField('external_identifier', array('label' => 'External ID'));
$form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
}
}
示例3: buildQuickForm
/**
* Build the form object elements for an Website object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
*/
public static function buildQuickForm(&$form, $blockCount = NULL)
{
if (!$blockCount) {
$blockId = $form->get('Website_Block_Count') ? $form->get('Website_Block_Count') : 1;
} else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Website type select
$form->addField("website[{$blockId}][website_type_id]", array('entity' => 'website', 'class' => 'eight'));
//Website box
$form->addField("website[{$blockId}][url]", array('entity' => 'website'));
$form->addRule("website[{$blockId}][url]", ts('Enter a valid web address beginning with \'http://\' or \'https://\'.'), 'url');
}
示例4: buildQuickForm
/**
* Build the form object elements for an email object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE)
{
// passing this via the session is AWFUL. we need to fix this
if (!$blockCount) {
$blockId = $form->get('Email_Block_Count') ? $form->get('Email_Block_Count') : 1;
} else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//Email box
$form->addField("email[{$blockId}][email]", array('entity' => 'email'));
$form->addRule("email[{$blockId}][email]", ts('Email is not valid.'), 'email');
if (isset($form->_contactType) || $blockEdit) {
//Block type
$form->addField("email[{$blockId}][location_type_id]", array('entity' => 'email', 'placeholder' => NULL, 'class' => 'eight'));
//TODO: Refactor on_hold field to select.
$multipleBulk = CRM_Core_BAO_Email::isMultipleBulkMail();
//On-hold select
if ($multipleBulk) {
$holdOptions = array(0 => ts('- select -'), 1 => ts('On Hold Bounce'), 2 => ts('On Hold Opt Out'));
$form->addElement('select', "email[{$blockId}][on_hold]", '', $holdOptions);
} else {
$form->addField("email[{$blockId}][on_hold]", array('entity' => 'email', 'type' => 'advcheckbox'));
}
//Bulkmail checkbox
$form->assign('multipleBulk', $multipleBulk);
if ($multipleBulk) {
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
$form->addElement('advcheckbox', "email[{$blockId}][is_bulkmail]", NULL, '', $js);
} else {
$js = array('id' => "Email_" . $blockId . "_IsBulkmail");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "email[{$blockId}][is_bulkmail]", '', '', '1', $js);
}
//is_Primary radio
$js = array('id' => "Email_" . $blockId . "_IsPrimary");
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "email[{$blockId}][is_primary]", '', '', '1', $js);
if (CRM_Utils_System::getClassName($form) == 'CRM_Contact_Form_Contact') {
$form->add('textarea', "email[{$blockId}][signature_text]", ts('Signature (Text)'), array('rows' => 2, 'cols' => 40));
$form->add('wysiwyg', "email[{$blockId}][signature_html]", ts('Signature (HTML)'), array('rows' => 2, 'cols' => 40));
}
}
}
示例5: buildQuickForm
/**
* This function provides the HTML form elements that are specific.
* to the Household Contact Type
*
* @param CRM_Core_Form $form
* Form object.
* @param int $inlineEditMode
* ( 1 for contact summary.
* top bar form and 2 for display name edit )
*
* @return void
*/
public static function buildQuickForm(&$form, $inlineEditMode = NULL)
{
$form->applyFilter('__ALL__', 'trim');
if (!$inlineEditMode || $inlineEditMode == 1) {
// household_name
$form->addField('household_name');
}
if (!$inlineEditMode || $inlineEditMode == 2) {
// nick_name
$form->addField('nick_name');
$form->addField('contact_source', array('label' => ts('Source')));
}
if (!$inlineEditMode) {
$form->addField('external_identifier', array('label' => ts('External ID')));
$form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
}
}
示例6: buildQuickForm
/**
* Build the form object elements for Communication Preferences object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
*/
public static function buildQuickForm(&$form)
{
// since the pcm - preferred communication method is logically
// grouped hence we'll use groups of HTML_QuickForm
// checkboxes for DO NOT phone, email, mail
// we take labels from SelectValues
$privacy = $commPreff = $commPreference = array();
$privacyOptions = CRM_Core_SelectValues::privacy();
// we add is_opt_out as a separate checkbox below for display and help purposes so remove it here
unset($privacyOptions['is_opt_out']);
foreach ($privacyOptions as $name => $label) {
$privacy[] = $form->createElement('advcheckbox', $name, NULL, $label);
}
$form->addGroup($privacy, 'privacy', ts('Privacy'), ' <br/>');
// preferred communication method
$comm = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method', array('loclize' => TRUE));
foreach ($comm as $value => $title) {
$commPreff[] = $form->createElement('advcheckbox', $value, NULL, $title);
}
$form->addField('preferred_communication_method', array('entity' => 'contact', 'type' => 'CheckBoxGroup'));
$form->addField('preferred_language', array('entity' => 'contact'));
if (!empty($privacyOptions)) {
$commPreference['privacy'] = $privacyOptions;
}
if (!empty($comm)) {
$commPreference['preferred_communication_method'] = $comm;
}
//using for display purpose.
$form->assign('commPreference', $commPreference);
$form->addField('preferred_mail_format', array('entity' => 'contact', 'label' => ts('Email Format')));
$form->addField('is_opt_out', array('entity' => 'contact', 'label' => ts('NO BULK EMAILS (User Opt Out)')));
$form->addField('communication_style_id', array('entity' => 'contact', 'type' => 'RadioGroup'));
//check contact type and build filter clause accordingly for greeting types, CRM-4575
$greetings = self::getGreetingFields($form->_contactType);
foreach ($greetings as $greeting => $fields) {
$filter = array('contact_type' => $form->_contactType, 'greeting_type' => $greeting);
//add addressee in Contact form
$greetingTokens = CRM_Core_PseudoConstant::greeting($filter);
if (!empty($greetingTokens)) {
$form->addElement('select', $fields['field'], $fields['label'], array('' => ts('- select -')) + $greetingTokens);
//custom addressee
$form->addElement('text', $fields['customField'], $fields['customLabel'], CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', $fields['customField']), $fields['js']);
}
}
}
示例7: buildQuickForm
/**
* Build the form object elements for an IM object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $blockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $blockCount = NULL, $blockEdit = FALSE)
{
if (!$blockCount) {
$blockId = $form->get('IM_Block_Count') ? $form->get('IM_Block_Count') : 1;
} else {
$blockId = $blockCount;
}
$form->applyFilter('__ALL__', 'trim');
//IM provider select
$form->addField("im[{$blockId}][provider_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL));
//Block type select
$form->addField("im[{$blockId}][location_type_id]", array('entity' => 'im', 'class' => 'eight', 'placeholder' => NULL, 'option_url' => NULL));
//IM box
$form->addField("im[{$blockId}][name]", array('entity' => 'im'));
//is_Primary radio
$js = array('id' => 'IM_' . $blockId . '_IsPrimary');
if (!$blockEdit) {
$js['onClick'] = 'singleSelect( this.id );';
}
$form->addElement('radio', "im[{$blockId}][is_primary]", '', '', '1', $js);
}
示例8: buildQuickForm
/**
* Build the form object elements for a phone object.
*
* @param CRM_Core_Form $form
* Reference to the form object.
* @param int $addressBlockCount
* Block number to build.
* @param bool $blockEdit
* Is it block edit.
*/
public static function buildQuickForm(&$form, $addressBlockCount = NULL, $blockEdit = FALSE)
{
// passing this via the session is AWFUL. we need to fix this
if (!$addressBlockCount) {
$blockId = $form->get('Phone_Block_Count') ? $form->get('Phone_Block_Count') : 1;
} else {
$blockId = $addressBlockCount;
}
$form->applyFilter('__ALL__', 'trim');
//phone type select
$form->addField("phone[{$blockId}][phone_type_id]", array('entity' => 'phone', 'class' => 'eight', 'placeholder' => NULL));
//main phone number with crm_phone class
$form->addField("phone[{$blockId}][phone]", array('entity' => 'phone', 'class' => 'crm_phone twelve'));
$form->addField("phone[{$blockId}][phone_ext]", array('entity' => 'phone'));
if (isset($form->_contactType) || $blockEdit) {
//Block type select
$form->addField("phone[{$blockId}][location_type_id]", array('entity' => 'phone', 'class' => 'eight', 'placeholder' => NULL));
//is_Primary radio
$js = array('id' => 'Phone_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
$form->addElement('radio', "phone[{$blockId}][is_primary]", '', '', '1', $js);
}
// TODO: set this up as a group, we need a valid phone_type_id if we have a phone number
// $form->addRule( "location[$locationId][phone][$locationId][phone]", ts('Phone number is not valid.'), 'phone' );
}
示例9: buildQuickForm
/**
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form)
{
$form->removeElement('status_id');
$form->removeElement('priority_id');
$caseId = CRM_Utils_Array::first($form->_caseId);
$form->_caseType = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create');
$form->_caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'case_type_id');
if (!in_array($form->_caseTypeId, $form->_caseType)) {
$form->_caseType[$form->_caseTypeId] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $form->_caseTypeId, 'title');
}
$form->addField('case_type_id', array('context' => 'create', 'entity' => 'Case'));
// timeline
$form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), NULL, TRUE, array('onclick' => "return showHideByValue('is_reset_timeline','','resetTimeline','table-row','radio',false);"));
$form->addDateTime('reset_date_time', ts('Reset Start Date'), FALSE, array('formatType' => 'activityDateTime'));
}
示例10: 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.
*/
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->addField("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->addField("address[{$blockId}][is_primary]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js);
if (!$inlineEdit) {
$js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
}
$form->addField("address[{$blockId}][is_billing]", array('entity' => 'address', 'label' => ts('Primary location for this contact'), 'text' => ts('Primary location for this contact')) + $js);
// hidden element to store master address id
$form->addField("address[{$blockId}][master_id]", array('entity' => 'address', 'type' => 'hidden'));
$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', 'street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'country_id', 'state_province_id', 'county_id', 'geo_code_1', 'geo_code_2', 'street_number', 'street_name', 'street_unit');
foreach ($elements as $name) {
//Remove id from name, to allow comparison against enabled addressOtions.
$nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
// Skip fields which are not enabled in the address options.
if (empty($addressOptions[$nameWithoutID])) {
$continue = TRUE;
//Don't skip street parsed fields when parsing is enabled.
if (in_array($nameWithoutID, array('street_number', 'street_name', 'street_unit')) && !empty($addressOptions['street_address_parsing'])) {
$continue = FALSE;
}
if ($continue) {
continue;
}
}
if ($name == 'address_name') {
$name = 'name';
}
$params = array('entity' => 'address');
if ($name == 'postal_code_suffix') {
$params['label'] = ts('Suffix');
}
$form->addField("address[{$blockId}][{$name}]", $params);
}
$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();
foreach ($defaults as $key => $val) {
if (empty($val)) {
continue;
}
// inorder to set correct defaults for checkbox custom data, we need to converted flat key to array
// this works for all types custom data
$keyValues = explode('[', str_replace(']', '', $key));
$addressDefaults[$keyValues[0]][$keyValues[1]][$keyValues[2]] = $val;
}
//.........这里部分代码省略.........
示例11: buildQuickForm
/**
* Build form elements.
*
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form)
{
$form->applyFilter('__ALL__', 'trim');
$form->addField('subject', array('entity' => 'note', 'size' => '60'));
$form->addField('note', array('entity' => 'note', 'rows' => 3));
}
示例12: buildSearchForm
/**
* Add all the elements shared between case search and advanced search.
*
* @param CRM_Core_Form $form
*/
public static function buildSearchForm(&$form)
{
$config = CRM_Core_Config::singleton();
//validate case configuration.
$configured = CRM_Case_BAO_Case::isCaseConfigured();
$form->assign('notConfigured', !$configured['configured']);
$form->addField('case_type_id', array('context' => 'search', 'entity' => 'Case'));
$form->addField('case_status_id', array('context' => 'search', 'entity' => 'Case'));
CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE);
$form->addElement('hidden', 'case_from_start_date_range_error');
$form->addElement('hidden', 'case_to_end_date_range_error');
$form->addFormRule(array('CRM_Case_BAO_Query', 'formRule'), $form);
$form->assign('validCiviCase', TRUE);
//give options when all cases are accessible.
$accessAllCases = FALSE;
if (CRM_Core_Permission::check('access all cases and activities')) {
$accessAllCases = TRUE;
$caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases'));
$form->addRadio('case_owner', ts('Cases'), $caseOwner);
}
$form->assign('accessAllCases', $accessAllCases);
$caseTags = CRM_Core_BAO_Tag::getTags('civicrm_case');
if ($caseTags) {
foreach ($caseTags as $tagID => $tagName) {
$form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", NULL, $tagName);
}
}
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_case', NULL, TRUE, FALSE);
if (CRM_Core_Permission::check('administer CiviCase')) {
$form->addElement('checkbox', 'case_deleted', ts('Deleted Cases'));
}
// add all the custom searchable fields
$extends = array('Case');
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends);
if ($groupDetails) {
$form->assign('caseGroupTree', $groupDetails);
foreach ($groupDetails as $group) {
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
$form->setDefaults(array('case_owner' => 1));
}
示例13: buildQuickForm
/**
* Build the form object.
*
* @param CRM_Core_Form $form
* Form object.
*
* @return void
*/
public static function buildQuickForm(&$form)
{
$form->addField('modified_date', array('type' => 'hidden', 'id' => 'modified_date', 'label' => ''));
}