本文整理汇总了PHP中CRM_Core_Form::addUploadElement方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_Form::addUploadElement方法的具体用法?PHP CRM_Core_Form::addUploadElement怎么用?PHP CRM_Core_Form::addUploadElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_Form
的用法示例。
在下文中一共展示了CRM_Core_Form::addUploadElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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
//.........这里部分代码省略.........
示例2: buildAttachment
/**
* @param CRM_Core_Form $form
* @param string $entityTable
* @param int $entityID
* @param null $numAttachments
* @param bool $ajaxDelete
*/
public static function buildAttachment(&$form, $entityTable, $entityID = NULL, $numAttachments = NULL, $ajaxDelete = FALSE)
{
if (!$numAttachments) {
$numAttachments = Civi::settings()->get('max_attachments');
}
// Assign maxAttachments count to template for help message
$form->assign('maxAttachments', $numAttachments);
$config = CRM_Core_Config::singleton();
// set default max file size as 2MB
$maxFileSize = $config->maxFileSize ? $config->maxFileSize : 2;
$currentAttachmentInfo = self::getEntityFile($entityTable, $entityID, TRUE);
$totalAttachments = 0;
if ($currentAttachmentInfo) {
$totalAttachments = count($currentAttachmentInfo);
$form->add('checkbox', 'is_delete_attachment', ts('Delete All Attachment(s)'));
$form->assign('currentAttachmentInfo', $currentAttachmentInfo);
} else {
$form->assign('currentAttachmentInfo', NULL);
}
if ($totalAttachments) {
if ($totalAttachments >= $numAttachments) {
$numAttachments = 0;
} else {
$numAttachments -= $totalAttachments;
}
}
$form->assign('numAttachments', $numAttachments);
CRM_Core_BAO_Tag::getTags('civicrm_file', $tags, NULL, ' ', TRUE);
// get tagset info
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_file');
// add attachments
for ($i = 1; $i <= $numAttachments; $i++) {
$form->addElement('file', "attachFile_{$i}", ts('Attach File'), 'size=30 maxlength=60');
$form->addUploadElement("attachFile_{$i}");
$form->setMaxFileSize($maxFileSize * 1024 * 1024);
$form->addRule("attachFile_{$i}", ts('File size should be less than %1 MByte(s)', array(1 => $maxFileSize)), 'maxfilesize', $maxFileSize * 1024 * 1024);
$form->addElement('text', "attachDesc_{$i}", NULL, array('size' => 40, 'maxlength' => 255, 'placeholder' => ts('Description')));
if (!empty($tags)) {
$form->add('select', "tag_{$i}", ts('Tags'), $tags, FALSE, array('id' => "tags_{$i}", 'multiple' => 'multiple', 'class' => 'huge crm-select2', 'placeholder' => ts('- none -')));
}
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_file', NULL, FALSE, TRUE, "file_taglist_{$i}");
}
}
示例3: addQuickFormElement
//.........这里部分代码省略.........
}
$qf->add('select', $elementName, $label, $options, $useRequired && !$search, $selectAttributes);
// Add and/or option for fields that store multiple values
if ($search && self::isSerialized($field)) {
$operators = array($qf->createElement('radio', NULL, '', ts('Any'), 'or', array('title' => ts('Results may contain any of the selected options'))), $qf->createElement('radio', NULL, '', ts('All'), 'and', array('title' => ts('Results must have all of the selected options'))));
$qf->addGroup($operators, $elementName . '_operator');
$qf->setDefaults(array($elementName . '_operator' => 'or'));
}
break;
case 'AdvMulti-Select':
$include =& $qf->addElement('advmultiselect', $elementName, $label, $options, array('size' => 5, 'style' => '', 'class' => 'advmultiselect', 'data-crm-custom' => $dataCrmCustomVal));
$include->setButtonAttributes('add', array('value' => ts('Add >>')));
$include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'CheckBox':
$check = array();
foreach ($options as $v => $l) {
$check[] =& $qf->addElement('advcheckbox', $v, NULL, $l, array('data-crm-custom' => $dataCrmCustomVal));
}
$qf->addGroup($check, $elementName, $label);
if ($useRequired && !$search) {
$qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
}
break;
case 'File':
// we should not build upload file in search mode
if ($search) {
return;
}
$qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search);
$qf->addUploadElement($elementName);
break;
case 'RichTextEditor':
$attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal);
if ($field->text_length) {
$attributes['maxlength'] = $field->text_length;
}
$qf->addWysiwyg($elementName, $label, $attributes, $search);
break;
case 'Autocomplete-Select':
static $customUrls = array();
// Fixme: why is this a string in the first place??
$attributes = array();
if ($field->attributes) {
foreach (explode(' ', $field->attributes) as $at) {
if (strpos($at, '=')) {
list($k, $v) = explode('=', $at);
$attributes[$k] = trim($v, ' "');
}
}
}
if ($field->data_type == 'ContactReference') {
$attributes['class'] = (isset($attributes['class']) ? $attributes['class'] . ' ' : '') . 'crm-form-contact-reference huge';
$attributes['data-api-entity'] = 'contact';
$qf->add('text', $elementName, $label, $attributes, $useRequired && !$search);
$urlParams = "context=customfield&id={$field->id}";
$customUrls[$elementName] = CRM_Utils_System::url('civicrm/ajax/contactref', $urlParams, FALSE, NULL, FALSE);
} else {
// FIXME: This won't work with customFieldOptions hook
$attributes += array('entity' => 'option_value', 'placeholder' => $placeholder, 'multiple' => $search, 'api' => array('params' => array('option_group_id' => $field->option_group_id)));
$qf->addEntityRef($elementName, $label, $attributes, $useRequired && !$search);
}
$qf->assign('customUrls', $customUrls);