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


PHP Pieform::element_descriptors方法代码示例

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


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

示例1: pieform_element_bytes

/**
 * Provides a size chooser, with a text box for a number and a
 * select box to choose the units, in bytes, kilobytes, megabytes or gigabytes
 *
 * @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_bytes(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    $result = '';
    $name = Pieform::hsc($element['name']);
    if (!isset($element['defaultvalue'])) {
        $element['defaultvalue'] = null;
    }
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    // Get the value of the element for rendering.
    if (isset($element['value'])) {
        $bytes = $element['value'];
        $values = pieform_element_bytes_get_bytes_from_bytes($element['value']);
    } else {
        if ($form->is_submitted() && isset($global[$element['name']]) && isset($global[$element['name'] . '_units'])) {
            $values = array('number' => $global[$element['name']], 'units' => $global[$element['name'] . '_units']);
            $bytes = $values['number'] * pieform_element_bytes_in($values['units']);
        } else {
            if (isset($element['defaultvalue'])) {
                $bytes = $element['defaultvalue'];
                $values = pieform_element_bytes_get_bytes_from_bytes($bytes);
            } else {
                $values = array('number' => '0', 'units' => 'bytes');
                $bytes = 0;
            }
        }
    }
    // @todo probably create with an actual input element, as tabindex doesn't work here for one thing
    // Same with the select. And do the events using mochikit signal instead of dom events
    $numberinput = '<div class="with-dropdown js-with-dropdown text">';
    $numberinput .= '<label for="' . $formname . '_' . $name . '">' . Pieform::hsc($element['title']) . ': </label><input';
    $numberinput .= ' type="text" size="6" name="' . $name . '"';
    $numberinput .= ' id="' . $formname . '_' . $name . '" value="' . Pieform::hsc($values['number']) . '" tabindex="' . Pieform::hsc($element['tabindex']) . '"';
    $numberinput .= 'class="with-dropdown js-with-dropdown form-control text' . (isset($element['error']) ? ' error"' : '') . '"';
    if (isset($element['description'])) {
        $numberinput .= ' aria-describedby="' . $form->element_descriptors($element) . '"';
    }
    $numberinput .= "></div>\n";
    $uselect = '<div class="dropdown-connect js-dropdown-connect select">';
    $uselect .= '<label for="' . $formname . '_' . $name . '_units" class="accessible-hidden sr-only">' . get_string('units') . '</label>';
    $uselect .= '<span class="picker"><select class="form-control dropdown-connect js-dropdown-connect select" name="' . $name . '_units" id="' . $formname . '_' . $name . '_units"' . ' tabindex="' . Pieform::hsc($element['tabindex']) . '"';
    if (isset($element['description'])) {
        $uselect .= ' aria-describedby="' . $form->element_descriptors($element) . '"';
    }
    $uselect .= ">\n";
    foreach (pieform_element_bytes_get_bytes_units() as $u) {
        $uselect .= "\t<option value=\"{$u}\"" . ($values['units'] == $u ? ' selected="selected"' : '') . '>' . $form->i18n('element', 'bytes', $u, $element) . "</option>\n";
    }
    $uselect .= "</select></span></div>\n";
    $fieldset = '<div id="' . $formname . '_' . $name . '_fieldset" class="dropdown-group js-dropdown-group form-group">' . '<fieldset class="pieform-fieldset dropdown-group js-dropdown-group">' . $numberinput . $uselect . '</fieldset></div>';
    return $fieldset;
}
开发者ID:rboyatt,项目名称:mahara,代码行数:61,代码来源:bytes.php

示例2: pieform_element_tags

/**
 * Provides a tag input field
 *
 * @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_tags(Pieform $form, $element)
{
    $smarty = smarty_core();
    $value = array();
    if (isset($element['defaultvalue']) && is_array($element['defaultvalue'])) {
        $value = $element['defaultvalue'];
    }
    if ($tempvalue = $form->get_value($element)) {
        $value = $tempvalue;
    }
    if (isset($element['value']) && is_array($element['value'])) {
        $value = $element['value'];
    }
    if (!is_array($value)) {
        $value = array();
    }
    if (!isset($element['size'])) {
        $element['size'] = 60;
    }
    $smarty->assign('name', $element['name']);
    $smarty->assign('size', $element['size']);
    $smarty->assign('id', $form->get_name() . '_' . $element['id']);
    $smarty->assign('value', join(', ', $value));
    if (isset($element['description'])) {
        $smarty->assign('describedby', $form->element_descriptors($element));
    }
    $smarty->left_delimiter = '{{';
    $smarty->right_delimiter = '}}';
    return $smarty->fetch('form/tags.tpl');
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:37,代码来源:tags.php

示例3: pieform_element_emaillist

/**
 * Provides an email list, with verification to enable addresses
 *
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_emaillist(Pieform $form, $element)
{
    $smarty = smarty_core();
    $smarty->left_delimiter = '{{';
    $smarty->right_delimiter = '}}';
    $value = $form->get_value($element);
    if (!is_array($value) && isset($element['defaultvalue']) && is_array($element['defaultvalue'])) {
        $value = $element['defaultvalue'];
    }
    if (!isset($value['validated'])) {
        $value['validated'] = array();
    }
    if (!isset($value['unvalidated'])) {
        $value['unvalidated'] = array();
    }
    if (!isset($value['unsent'])) {
        $value['unsent'] = array();
    }
    if (!isset($value['default'])) {
        $value['default'] = '';
    }
    if (is_array($value) && count($value)) {
        $smarty->assign('validated', $value['validated']);
        $smarty->assign('unvalidated', $value['unvalidated']);
        $smarty->assign('unsent', $value['unsent']);
        $smarty->assign('default', $value['default']);
    }
    $smarty->assign('form', $form->get_name());
    $smarty->assign('name', $element['name']);
    $smarty->assign('title', $element['title']);
    $smarty->assign('addbuttonstr', get_string('addbutton', 'artefact.internal'));
    $smarty->assign('validationemailstr', json_encode(get_string('validationemailwillbesent', 'artefact.internal')));
    $smarty->assign('disabled', !empty($element['disabled']));
    if (isset($element['description'])) {
        $smarty->assign('describedby', $form->element_descriptors($element));
    }
    return $smarty->fetch('form/emaillist.tpl');
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:45,代码来源:emaillist.php

示例4: pieform_element_autocomplete

/**
 * Autocomplete list selector element
 *
 * @param array    $element The element to render
 * @param Pieform  $form    The form to render the element for
 * @return string           The HTML for the element
 */
function pieform_element_autocomplete(Pieform $form, $element)
{
    global $USER;
    $wwwroot = get_config('wwwroot');
    $smarty = smarty_core();
    $smarty->left_delimiter = '{{';
    $smarty->right_delimiter = '}}';
    $value = $form->get_value($element);
    $multiple = !empty($element['multiple']);
    if ($multiple) {
        $valuestr = implode(',', $value);
    } else {
        $valuestr = $value;
    }
    if (!empty($element['initfunction'])) {
        $initvalue = json_encode(call_user_func($element['initfunction'], $value));
    } else {
        $initvalue = '[]';
    }
    if (array_key_exists('mininputlength', $element)) {
        $mininputlength = $element['mininputlength'];
    } else {
        $mininputlength = 1;
    }
    $extraparams = '';
    if (!empty($element['extraparams'])) {
        foreach ($element['extraparams'] as $k => $v) {
            if (!is_numeric($v)) {
                if (preg_match('/^\'(.*)\'$/', $v, $match)) {
                    $v = $match[1];
                }
                $element['extraparams'][$k] = json_encode($v);
            }
            $extraparams .= $k . ': ' . $element['extraparams'][$k] . ',';
        }
    }
    $smarty->assign('id', $form->get_name() . '_' . $element['id']);
    $smarty->assign('name', $element['name']);
    $smarty->assign('value', $valuestr);
    // Pre-populate form element.
    $smarty->assign('initvalue', $initvalue);
    $smarty->assign('width', empty($element['width']) ? '300px' : $element['width']);
    $smarty->assign('multiple', $multiple ? 'true' : 'false');
    $smarty->assign('mininputlength', $mininputlength);
    $smarty->assign('allowclear', empty($element['allowclear']) ? 'false' : 'true');
    $smarty->assign('disabled', !empty($element['disabled']) ? 'true' : 'false');
    $smarty->assign('ajaxurl', $element['ajaxurl']);
    $smarty->assign('sesskey', $USER->get('sesskey'));
    $smarty->assign('hint', empty($element['hint']) ? get_string('defaulthint') : $element['hint']);
    $smarty->assign('extraparams', $extraparams);
    if (isset($element['description'])) {
        $smarty->assign('describedby', $form->element_descriptors($element));
    }
    return $smarty->fetch('form/autocomplete.tpl');
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:62,代码来源:autocomplete.php

示例5: pieform_element_expiry

/**
 * Provides a duration chooser, with a text box for a number and a
 * select box to choose the units, in days, weeks, months, years, or 'no end date'.
 *
 * @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_expiry(Pieform $form, $element)
{
    /*{{{*/
    $formname = $form->get_name();
    $result = '';
    $name = Pieform::hsc($element['name']);
    if (!isset($element['defaultvalue'])) {
        $element['defaultvalue'] = null;
    }
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    // Get the value of the element for rendering.
    if (isset($element['value'])) {
        $seconds = $element['value'];
        $values = pieform_element_expiry_get_expiry_from_seconds($element['value']);
    } else {
        if ($form->is_submitted() && isset($global[$element['name']]) && isset($global[$element['name'] . '_units'])) {
            $values = array('number' => $global[$element['name']], 'units' => $global[$element['name'] . '_units']);
            $seconds = $values['number'] * pieform_element_expiry_seconds_in($values['units']);
        } else {
            if (isset($element['defaultvalue'])) {
                $seconds = $element['defaultvalue'];
                $values = pieform_element_expiry_get_expiry_from_seconds($seconds);
            } else {
                $values = array('number' => '', 'units' => 'noenddate');
                $seconds = null;
            }
        }
    }
    // @todo probably create with an actual input element, as tabindex doesn't work here for one thing
    // Same with the select. And do the events using mochikit signal instead of dom events
    $numberinput = '<input';
    $numberinput .= $values['units'] == 'noenddate' && empty($element['rules']['required']) ? ' disabled="disabled"' : '';
    $numberinput .= ' type="text" size="4" name="' . $name . '"';
    $numberinput .= ' id="' . $formname . '_' . $name . '" value="' . Pieform::hsc($values['number']) . '" tabindex="' . Pieform::hsc($element['tabindex']) . '"';
    if (isset($element['description'])) {
        $numberinput .= ' aria-describedby="' . $form->element_descriptors($element) . '"';
    }
    $numberinput .= (isset($element['error']) ? ' class="error"' : '') . ">\n";
    $uselect = '<label for="' . $formname . '_' . $name . '_units" class="accessible-hidden">' . get_string('units', 'mahara') . '</label>';
    $uselect .= '<select onchange="' . $name . '_change()" ';
    $uselect .= 'name="' . $name . '_units" id="' . $formname . '_' . $name . '_units"' . ' tabindex="' . Pieform::hsc($element['tabindex']) . '"';
    if (isset($element['description'])) {
        $uselect .= ' aria-describedby="' . $form->element_descriptors($element) . '"';
    }
    $uselect .= ">\n";
    foreach (pieform_element_expire_get_expiry_units() as $u) {
        // Don't allow 'no end date' if the element is required
        if ($u == 'noenddate' && !empty($element['rules']['required'])) {
            continue;
        }
        $uselect .= "\t<option value=\"{$u}\"" . ($values['units'] == $u ? ' selected="selected"' : '') . '>' . $form->i18n('element', 'expiry', $u, $element) . "</option>\n";
    }
    $uselect .= "</select>\n";
    // Make sure the input is disabled if "no end date" is selected
    $script = <<<EOJS
<script type="application/javascript" language="javascript">
function {$name}_change() {
    if (\$('{$formname}_{$name}_units').value == 'noenddate') {
        \$('{$formname}_{$name}').disabled = true;
    }
    else {
        \$('{$formname}_{$name}').disabled = false;
    }
}
</script>
EOJS;
    return $numberinput . $uselect . $script;
}
开发者ID:vohung96,项目名称:mahara,代码行数:76,代码来源:expiry.php


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