本文整理汇总了PHP中FormElement::setTypeAsCheckbox方法的典型用法代码示例。如果您正苦于以下问题:PHP FormElement::setTypeAsCheckbox方法的具体用法?PHP FormElement::setTypeAsCheckbox怎么用?PHP FormElement::setTypeAsCheckbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormElement
的用法示例。
在下文中一共展示了FormElement::setTypeAsCheckbox方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createElementObject
/**
* Convert an array of details into a form element.
* @param String $fieldName The name of the form element
* @param Array $fieldDetails The list of details for the form element.
*/
protected function createElementObject($fieldName, $fieldDetails)
{
// Extract fields
$label = $this->formObj->getArrayValue($fieldDetails, 'label');
$type = $this->formObj->getArrayValue($fieldDetails, 'type');
// Required 'true' or true are valid
$required = $this->formObj->getArrayValue($fieldDetails, 'required');
$required = $required == 'true' || $required == '1';
// Start creating form element if anything other than a break.
$elem = false;
if ($type != 'break') {
$elem = new FormElement($fieldName, $label, $required);
}
// Handle specific types
switch ($type) {
// Text Area
case 'textarea':
$rows = $this->formObj->getArrayValue($fieldDetails, 'rows') + 0;
if ($rows == 0) {
$rows = 5;
}
$elem->setTypeAsTextArea($rows, 70);
break;
// Select/Dropdown
// Select/Dropdown
case 'select':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsComboBox($options);
break;
// Radio Buttons
// Radio Buttons
case 'radio':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsRadioButtons($options);
break;
// Checkbox
// Checkbox
case 'checkbox':
$label = false;
if (isset($fieldDetails['extralabel'])) {
$label = $fieldDetails['extralabel'];
}
$elem->setTypeAsCheckbox($label);
break;
// Checkbox List
// Checkbox List
case 'checkboxlist':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsCheckboxList($options);
break;
// Merged Fields - process each sub element
// Merged Fields - process each sub element
case 'merge':
$elementList = array();
if (!empty($fieldDetails['merge'])) {
foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) {
$elementList[] = $this->createElementObject($fieldName, $fieldDetails);
}
}
$elem->setTypeAsMergedElements($elementList);
break;
// File upload
// File upload
case 'uploadfile':
$elem->setTypeAsUploadFile($this->formObj->getArrayValue($fieldDetails, 'show_existing'), $this->formObj->getArrayValue($fieldDetails, 'valid_if_value'));
break;
// Custom HTML
// Custom HTML
case 'custom':
$elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Hidden field
// Hidden field
case 'hidden':
$elem->setTypeAsHidden();
break;
// Section break
// Section break
case 'break':
$this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Text box
// Text box
default:
break;
}
//.........这里部分代码省略.........
示例2: WPPortfolio_showLayoutSettingsPage
/**
* Show only the settings relating to layout of the portfolio.
*/
function WPPortfolio_showLayoutSettingsPage()
{
?>
<div class="wrap">
<div id="icon-themes" class="icon32">
<br/>
</div>
<h2>WP Portfolio - Layout Settings</h2>
<?php
// Get all the options from the database
$settingsList = WPPortfolio_getSettingList(false, true);
// Get all the options from the database for the form
$settings = array();
foreach ($settingsList as $settingName => $settingDefault) {
$settings[$settingName] = stripslashes(get_option('WPPortfolio_' . $settingName));
}
// If we don't have the version in the settings, we're not installed
if (!get_option('WPPortfolio_version')) {
WPPortfolio_showMessage(__('No WP Portfolio settings were found, so it appears that the plugin has been uninstalled. Please <b>deactivate</b> and then <b>activate</b> the WP Portfolio plugin again to fix this.', 'wp-portfolio'), true);
return false;
}
// Check if updated data.
if (isset($_POST) && isset($_POST['update'])) {
// Copy settings from $_POST
$settings = array();
foreach ($settingsList as $settingName => $settingDefault) {
$settings[$settingName] = stripslashes(trim(WPPortfolio_getArrayValue($_POST, $settingName)));
}
// Save settings
foreach ($settingsList as $settingName => $settingDefault) {
update_option('WPPortfolio_' . $settingName, $settings[$settingName]);
}
WPPortfolio_showMessage();
}
$form = new FormBuilder();
$formElem = new FormElement("setting_template_website", __("Website HTML Template", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_website']);
$formElem->description = '• ' . __('This is the template used to render each of the websites.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('A complete list of tags is available in the <a href="%s#doc-layout">Portfolio Layout Templates</a> section in the documentation.', 'wp-portfolio'), WPP_DOCUMENTATION);
$formElem->setTypeAsTextArea(8, 70);
$form->addFormElement($formElem);
$formElem = new FormElement("setting_template_group", __("Group HTML Template", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_group']);
$formElem->description = '• ' . __('This is the template used to render each of the groups that the websites belong to.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('A complete list of tags is available in the <a href="%s#doc-layout">Portfolio Layout Templates</a> section in the documentation.', 'wp-portfolio'), WPP_DOCUMENTATION);
$formElem->setTypeAsTextArea(3, 70);
$form->addFormElement($formElem);
$form->addBreak('settings_paging', '<div class="settings-spacer"> </div><h2>' . __('Portfolio Paging Settings', 'wp-portfolio') . '</h2>');
$formElem = new FormElement("setting_template_paging", __("Paging HTML Template", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_paging']);
$formElem->description = '• ' . __('This is the template used to render the paging for the thumbnails.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('A complete list of tags is available in the <a href="%s#doc-paging">Portfolio Paging Templates</a> section in the documentation.', 'wp-portfolio'), WPP_DOCUMENTATION);
$formElem->setTypeAsTextArea(3, 70);
$form->addFormElement($formElem);
$formElem = new FormElement("setting_template_paging_previous", __("Text for 'Previous' link", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_paging_previous']);
$formElem->description = __('The text to use for the \'Previous\' page link used in the thumbnail paging.', 'wp-portfolio');
$form->addFormElement($formElem);
$formElem = new FormElement("setting_template_paging_next", __("Text for 'Next' link", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_paging_next']);
$formElem->description = __('The text to use for the \'Next\' page link used in the thumbnail paging.', 'wp-portfolio');
$form->addFormElement($formElem);
$form->addBreak('settings_css', '<div class="settings-spacer"> </div><h2>' . __('Portfolio Stylesheet (CSS) Settings', 'wp-portfolio') . '</h2>');
// Enable/Disable CSS mode
$formElem = new FormElement("setting_disable_plugin_css", __("Disable Plugin CSS", 'wp-portfolio'));
$formElem->value = $settings['setting_disable_plugin_css'];
$formElem->setTypeAsCheckbox(__("If ticked, don't use the WP Portfolio CSS below.", 'wp-portfolio'));
$formElem->description = '• ' . __('Allows you to switch off the default CSS so that you can use CSS in your template CSS file.', 'wp-portfolio') . '<br/>' . sprintf('• ' . __('<strong>Advanced Tip:</strong> Once you\'re happy with the styles, you should really move all the CSS below into your template %s. This is so that visitor browsers can cache the stylesheet and reduce loading times. Any CSS placed here will be injected into the template <head> tag, which is not the most efficient method of delivering CSS.', 'wp-portfolio'), '<code>style.css</code>');
$form->addFormElement($formElem);
$formElem = new FormElement("setting_template_css", __("Template CSS", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_css']);
$formElem->description = __('This is the CSS code used to style the portfolio.', 'wp-portfolio');
$formElem->setTypeAsTextArea(10, 70);
$form->addFormElement($formElem);
$formElem = new FormElement("setting_template_css_paging", __("Paging CSS", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_css_paging']);
$formElem->description = __('This is the CSS code used to style the paging area if you are showing your portfolio on several pages.', 'wp-portfolio');
$formElem->setTypeAsTextArea(6, 70);
$form->addFormElement($formElem);
$formElem = new FormElement("setting_template_css_widget", __("Widget CSS", 'wp-portfolio'));
$formElem->value = htmlentities($settings['setting_template_css_widget']);
$formElem->description = __('This is the CSS code used to style the websites in the widget area.', 'wp-portfolio');
$formElem->setTypeAsTextArea(6, 70);
$form->addFormElement($formElem);
echo $form->toString();
?>
</div>
<?php
}
示例3: createElementObject
/**
* Convert an array of details into a form element.
* @param String $fieldName The name of the form element
* @param Array $fieldDetails The list of details for the form element.
*/
protected function createElementObject($fieldName, $fieldDetails)
{
// Extract fields
$label = $this->formObj->getArrayValue($fieldDetails, 'label');
$type = $this->formObj->getArrayValue($fieldDetails, 'type');
// Required 'true' or true are valid
$required = $this->formObj->getArrayValue($fieldDetails, 'required');
$required = $required == 'true' || $required == '1';
// Start creating form element if anything other than a break.
$elem = false;
if ($type != 'break') {
$elem = new FormElement($fieldName, $label, $required);
}
// Handle specific types
switch ($type) {
// Text Area
case 'textarea':
$rows = $this->formObj->getArrayValue($fieldDetails, 'rows') + 0;
if ($rows == 0) {
$rows = 5;
}
$elem->setTypeAsTextArea($rows, 70);
break;
// Select/Dropdown
// Select/Dropdown
case 'select':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsComboBox($options);
break;
// Radio Buttons
// Radio Buttons
case 'radio':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsRadioButtons($options);
break;
// Checkbox
// Checkbox
case 'checkbox':
$label = false;
if (isset($fieldDetails['extralabel'])) {
$label = $fieldDetails['extralabel'];
}
$elem->setTypeAsCheckbox($label);
break;
// Checkbox List
// Checkbox List
case 'checkboxlist':
$options = false;
if (isset($fieldDetails['data']) && is_array($fieldDetails['data'])) {
$options = $fieldDetails['data'];
}
$elem->setTypeAsCheckboxList($options);
break;
// Merged Fields - process each sub element
// Merged Fields - process each sub element
case 'merge':
$elementList = array();
if (!empty($fieldDetails['merge'])) {
foreach ($fieldDetails['merge'] as $fieldName => $fieldDetails) {
$elementList[] = $this->createElementObject($fieldName, $fieldDetails);
}
}
$elem->setTypeAsMergedElements($elementList);
break;
// Custom HTML
// Custom HTML
case 'custom':
$elem->setTypeAsCustom($this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Hidden field
// Hidden field
case 'hidden':
$elem->setTypeAsHidden();
break;
// Section break
// Section break
case 'break':
$this->formObj->addBreak($fieldName, $this->formObj->getArrayValue($fieldDetails, 'html'));
break;
// Text box
// Text box
default:
break;
}
// Add optional fields
if ($type != 'break') {
// Element description
if ($desc = $this->formObj->getArrayValue($fieldDetails, 'desc')) {
$elem->description = $desc;
//.........这里部分代码省略.........