本文整理汇总了PHP中FormElement::setTypeAsCheckboxList方法的典型用法代码示例。如果您正苦于以下问题:PHP FormElement::setTypeAsCheckboxList方法的具体用法?PHP FormElement::setTypeAsCheckboxList怎么用?PHP FormElement::setTypeAsCheckboxList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormElement
的用法示例。
在下文中一共展示了FormElement::setTypeAsCheckboxList方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showMembershipMappingLevels_specificLevel
/**
* Show the form for editing the specific courses a user can access based on what level that they have access to.
* @param PageBuilder $page The page rendering object.
* @param Array $levelDetails The list of level details
*/
private function showMembershipMappingLevels_specificLevel($page, $levelDetails)
{
// Show a nice summary of what level is being edited.
printf('<div id="wpcw_member_level_name_title">%s</div>', sprintf(__('Editing permissions for <b>%s</b> level with <b>%s</b>:', 'wp_courseware'), $levelDetails['name'], $this->extensionName));
// Get a list of course IDs that exist
$courses = WPCW_courses_getCourseList(false);
// Get list of courses already associated with level.
$courseListInDB = $this->getCourseAccessListForLevel($levelDetails['id']);
// Create the summary URL to return
$summaryURL = admin_url('admin.php?page=' . $this->extensionID);
// Update form...
$form = new FormBuilder('wpcw_member_levels_edit');
$form->setSubmitLabel(__('Save Changes', 'wp_courseware'));
// Create list of courses using checkboxes (max of 2 columns)
$elem = new FormElement('level_courses', __('Courses user can access at this level', 'wp_courseware'), false);
$elem->setTypeAsCheckboxList($courses);
$elem->checkboxListCols = 2;
$form->addFormElement($elem);
// Normally would check for errors too, but there's not a lot to check here.
if ($form->formSubmitted()) {
if ($form->formValid()) {
$mapplingList = $form->getValue('level_courses');
global $wpdb, $wpcwdb;
$wpdb->show_errors();
// Remove all previous level mappings (as some will have been removed)
$wpdb->query($wpdb->prepare("\n\t\t\t\t\t\tDELETE \n\t\t\t\t\t\tFROM {$wpcwdb->map_member_levels} \n\t\t\t\t\t\tWHERE member_level_id = %s\n\t\t\t\t\t", $levelDetails['id']));
// Add all of the new mappings the user has chosen.
if ($mapplingList && count($mapplingList) > 0) {
foreach ($mapplingList as $courseID => $itemState) {
$wpdb->query($wpdb->prepare("\n\t\t\t\t\t\t\t\tINSERT INTO {$wpcwdb->map_member_levels} \n\t\t\t\t\t\t\t\t(course_id, member_level_id) \n\t\t\t\t\t\t\t\tVALUES (%d, %s)\n\t\t\t\t\t\t\t", $courseID, $levelDetails['id']));
}
}
// Show a success message.
$page->showMessage(__('Level and course permissions successfully updated.', 'wp_courseware') . '<br/><br/>' . sprintf(__('Want to return to the <a href="%s">Course Access Settings summary</a>?', 'wp_courseware'), $summaryURL));
}
// if ($form->formValid())
} else {
$form->setDefaultValues(array('level_courses' => $courseListInDB));
}
// Show the form
echo $form->toString();
printf('<a href="%s" class="button-secondary">%s</a>', $summaryURL, __('« Return to Course Access Settings summary', 'wp_courseware'));
}
示例2: 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;
}
//.........这里部分代码省略.........
示例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;
//.........这里部分代码省略.........