当前位置: 首页>>代码示例>>PHP>>正文


PHP Pieform::make_id方法代码示例

本文整理汇总了PHP中Pieform::make_id方法的典型用法代码示例。如果您正苦于以下问题:PHP Pieform::make_id方法的具体用法?PHP Pieform::make_id怎么用?PHP Pieform::make_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pieform的用法示例。


在下文中一共展示了Pieform::make_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: pieform_element_select

/**
 * Renders a dropdown list, including support for multiple choices.
 *
 * Configuration options:
 *
 * In addition to the standard pieform element configuration options, the select element
 * can take these. Each one must include an "options", "optgroups", or "optionurl"
 * parameter, because otherwise it won't have any options.
 *
 * - "options" (array): The list of items in the menu. A little confusingly, the array key
 * for each array entry is used as the "value" attribute for the <option> tag. Each array
 * value should usually be a string, in which case it will be displayed as the text between
 * the <option> tags. Or for more advanced functionality each array value can be an array
 * with these keys:
 * --- "value": The string to display inside the <option> tags
 * --- "disabled" (boolean default false): Set to true to disable this option
 * --- "style": CSS styling to set on this option
 * --- "label": sets a "label" attribute on the <option> tag
 *
 * - "optgroups" (array of arrays): Provide this INSTEAD of "options" if you want to use
 * optgroups. This should be an array of arrays. Each entry in the array represents an
 * optgroup (the key is ignored). Each optgroup array should contain an item with the
 * key "label", which will be the user-displayed label, and an item with the key "options",
 * which should be a list of options to go in that outgroup, with the same format as a
 * standard "options" array.
 *
 * - "multiple" (boolean, default false): Indicates whether to allow multiple items to be selected
 *
 * - "collapseifoneoption" (boolean, default true): If there's only one option, print it as a string
 * instead of as a menu.
 *
 * - "allowother" (boolean, default false): Says to add an "other" free text field to the menu. If there
 * is a menu option with value "other", then selecting this will display the free text
 * field. If there is no menu option with value "other", one will be added to the option
 * list.
 *
 * - "width" (deprecated): How wide to make this select element in pixels. Better to do this with CSS.
 *
 * - "height" (deprecated): How tall to make this select element in pixels. Better to do this with CSS.
 *
 * @todo Currently, putting a junk defaultvalue/value for a multiple select
 * does not trigger any kind of error, it should perhaps trigger a
 * Pieform::info
 *
 * @param Pieform  $form    The form to render the element for
 * @param array    $element The element to render
 * @return string           The HTML for the element
 */
function pieform_element_select(Pieform $form, $element)
{
    if (!empty($element['multiple'])) {
        $element['name'] .= '[]';
    }
    if (!empty($element['allowother']) and !isset($element['options']['other'])) {
        $element['options']['other'] = get_string('element.select.other', 'pieforms');
    }
    $optionsavailable = true;
    $options = pieform_element_select_get_options($element);
    if (empty($options)) {
        $optionsavailable = false;
        Pieform::info('Select elements should have at least one option');
    }
    if (!empty($element['collapseifoneoption']) && is_array($options) && count($options) == 1) {
        foreach ($options as $key => $value) {
            if (is_array($value)) {
                $value = $value['value'];
            }
            $result = Pieform::hsc($value) . '<input type="hidden" id="' . $form->make_id($element, true) . '" name="' . Pieform::hsc($element['name']) . '" value="' . Pieform::hsc($key) . '">';
        }
        return $result;
    }
    $result = '<select' . $form->element_attributes($element) . (!empty($element['multiple']) ? ' multiple="multiple"' : '') . (!empty($element['allowother']) ? ' onChange="pieform_select_other(this);"' : '') . (!empty($element['width']) ? ' style="width: ' . $element['width'] . 'px;' : ' style="') . (!empty($element['height']) ? ' height: ' . $element['height'] . 'px;"' : '"') . ">\n";
    if (!$optionsavailable) {
        $result .= "\t<option></option>\n</select>";
        return $result;
    }
    $values = $form->get_value($element);
    $optionselected = false;
    if (!empty($element['allowother'])) {
        $use_other = $values;
        foreach ($element['options'] as $key => $value) {
            if (!is_array($values) && $key == $values || is_array($values) && in_array($key, $values)) {
                unset($use_other);
                break;
            }
        }
        if (isset($use_other)) {
            $values = 'other';
        }
    }
    if (empty($element['optgroups'])) {
        $result .= pieform_element_select_render_options($element['options'], $values, $optionselected, $element);
    } else {
        foreach ($element['optgroups'] as $optgroup) {
            $result .= "\t<optgroup label=\"" . hsc($optgroup['label']) . '">' . "\n" . pieform_element_select_render_options($optgroup['options'], $values, $optionselected, $element) . "\t</optgroup>\n";
        }
    }
    if (!$optionselected && !is_array($values) && $values !== null) {
        Pieform::info('Invalid value for select "' . $element['name'] . '"');
    }
//.........这里部分代码省略.........
开发者ID:vohung96,项目名称:mahara,代码行数:101,代码来源:select.php


注:本文中的Pieform::make_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。