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


PHP Pieform::element_attributes方法代码示例

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


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

示例1: pieform_element_button

/**
 * Renders an <input type="button"> element.
 *
 * The element must have the 'value' field set.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 * @todo rename to inputbutton
 */
function pieform_element_button(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value'])) {
        throw new PieformException('Button elements must have a value');
    }
    if (isset($element['confirm'])) {
        $element['data-confirm'] = Pieform::hsc($element['confirm']);
    }
    $element['class'] .= ' btn';
    if (isset($element['usebuttontag']) && $element['usebuttontag'] === true) {
        $value = '';
        $action = '';
        $type = 'type="submit" ';
        if (isset($element['content'])) {
            $content = $element['content'];
            $value = 'value="' . Pieform::hsc($element['value']) . '" ';
        } else {
            $content = $element['value'];
        }
        if (isset($element['action'])) {
            $action = 'formaction="' . Pieform::hsc($element['action']) . '" ';
        }
        $button = '<button ' . $value . $action . $type . $form->element_attributes($element) . '>' . $content . '</button>';
    } else {
        $button = '<input type="button"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($element['value']) . '">';
    }
    return $button;
}
开发者ID:rboyatt,项目名称:mahara,代码行数:39,代码来源:button.php

示例2: pieform_element_calendar

/**
 * Provides a javascript calendar for inputting a date.
 *
 * General documentation about the calendar is available at
 * http://www.dynarch.com/static/jscalendar-1.0/doc/html/reference.html
 *
 * @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_calendar(Pieform $form, $element)
{
    /*{{{*/
    $id = $form->get_name() . '_' . $element['name'];
    $value = $form->get_value($element);
    if ($value) {
        $value = Pieform::hsc(strftime($element['caloptions']['ifFormat'], $value));
    }
    // Build the HTML
    $result = '<input type="text"' . $form->element_attributes($element) . ' value="' . $value . '">';
    if (isset($element['imagefile'])) {
        $result .= '<a href="" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' . ' tabindex="' . $element['tabindex'] . '">' . '<img src="' . $element['imagefile'] . '" alt=""></a>';
    } else {
        $result .= '<input type="button" id="' . $id . '_btn" onclick="return false;" class="pieform-calendar-toggle"' . ' value="..." tabindex="' . $element['tabindex'] . '">';
    }
    // Build the configuring javascript
    $options = array_merge($element['caloptions'], array('inputField' => $id, 'button' => $id . '_btn'));
    $encodedoptions = json_encode($options);
    // Some options are callbacks and need their quoting removed
    foreach (array('dateStatusFunc', 'flatCallback', 'onSelect', 'onClose', 'onUpdate') as $function) {
        $encodedoptions = preg_replace('/("' . $function . '"):"([a-zA-Z0-9$]+)"/', '\\1:\\2', $encodedoptions);
    }
    $result .= '<script type="text/javascript">Calendar.setup(' . $encodedoptions . ');</script>';
    return $result;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:35,代码来源:calendar.php

示例3: pieform_element_textarea

/**
 * Renders a basic HTML <textarea> 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_textarea(Pieform $form, $element)
{
    /*{{{*/
    global $_PIEFORM_TEXTAREAS;
    $rows = $cols = $style = '';
    if (isset($element['height'])) {
        $style .= 'height:' . $element['height'] . ';';
        $rows = intval($element['height'] > 0) ? ceil(intval($element['height']) / 10) : 1;
    } elseif (isset($element['rows'])) {
        $rows = $element['rows'];
    } else {
        Pieform::info('No value for rows or height specified for textarea "' . $element['name'] . '"');
    }
    if (isset($element['width'])) {
        $style .= 'width:' . $element['width'] . ';';
        $cols = intval($element['width'] > 0) ? ceil(intval($element['width']) / 10) : 1;
    } elseif (isset($element['cols'])) {
        $cols = $element['cols'];
    } else {
        Pieform::info('No value for cols or width specified for textarea "' . $element['name'] . '"');
    }
    $element['style'] = isset($element['style']) ? $style . $element['style'] : $style;
    $fullwidth = !empty($element['fullwidth']) ? 'true' : 'false';
    if (!empty($element['resizable'])) {
        $element['class'] = isset($element['class']) && $element['class'] ? $element['class'] . ' resizable' : 'resizable';
        $_PIEFORM_TEXTAREAS[] = array('formname' => $form->get_name(), 'elementname' => $form->get_name() . '_' . $element['id'], 'fullwidth' => $fullwidth);
    }
    return '<textarea' . ($rows ? ' rows="' . $rows . '"' : '') . ($cols ? ' cols="' . $cols . '"' : '') . $form->element_attributes($element, array('maxlength', 'size')) . '>' . Pieform::hsc($form->get_value($element)) . '</textarea>';
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:36,代码来源:textarea.php

示例4: pieform_element_radio

/**
 * Renders a set of radio buttons for a form
 *
 * @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_radio(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) {
        throw new PieformException('Radio elements should have at least one option');
    }
    $result = '';
    $form_value = $form->get_value($element);
    $id = $element['id'];
    $separator = "\n";
    if (isset($element['separator'])) {
        $separator = $element['separator'] . $separator;
    }
    foreach ($element['options'] as $value => $data) {
        $uid = $id . substr(md5(microtime()), 0, 4);
        $element['id'] = $uid;
        if (is_array($data)) {
            $text = $data['text'];
            $description = isset($data['description']) ? $data['description'] : '';
        } else {
            $text = $data;
            $description = '';
        }
        $result .= '<input type="radio"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($value) . '"' . ($form_value == $value ? ' checked="checked"' : '') . '> <label for="' . $form->get_name() . '_' . $uid . '">' . Pieform::hsc($text) . "</label>" . ($description != '' ? '<div class="radio-description">' . $description . '</div>' : '') . $separator;
    }
    $result = substr($result, 0, -strlen($separator));
    return $result;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:35,代码来源:radio.php

示例5: pieform_element_hidden

/**
 * Renders a hidden element.
 *
 * @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_hidden(Pieform $form, $element)
{
    /*{{{*/
    if (!array_key_exists('value', $element)) {
        throw new PieformException('The hidden element "' . $element['name'] . '" must have a value set');
    }
    if (!empty($element['sesskey']) && $form->get_property('method') != 'post') {
        throw new PieformException('Sesskey values should be POSTed');
    }
    $value = $form->get_value($element);
    if (is_array($value)) {
        $result = '';
        foreach ($value as $k => $v) {
            if (is_array($v)) {
                foreach ($v as $subk => $subv) {
                    $result .= '<input type="hidden" name="' . Pieform::hsc($element['name']) . '[' . Pieform::hsc($k) . '][' . Pieform::hsc($subk) . ']" value="' . Pieform::hsc($subv) . "\">\n";
                }
            } else {
                $result .= '<input type="hidden" name="' . Pieform::hsc($element['name']) . '[' . Pieform::hsc($k) . ']" value="' . Pieform::hsc($v) . "\">\n";
            }
        }
        return $result;
    }
    return '<input type="hidden"' . $form->element_attributes($element, array('accesskey', 'onclick', 'size', 'style', 'tabindex')) . ' value="' . Pieform::hsc($form->get_value($element)) . "\">\n";
}
开发者ID:rboyatt,项目名称:mahara,代码行数:32,代码来源:hidden.php

示例6: pieform_element_passwordnoread

/**
 * Provides a password field that doesn't send the password text back to the user's browser.
 * If the value of the field is empty, then you get a standard input type=password.
 * If the field is non-empty, you get a link that says "Change password?" and if you click
 * on that, you get an input type=password.
 * The "Change password?" text can be customized by providing an "expandtext" value.
 *
 * @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_passwordnoread(Pieform $form, $element)
{
    if (isset($element['defaultvalue']) && $element['defaultvalue'] == '') {
        return '<input type="password"' . $form->element_attributes($element) . ' value="">';
    } else {
        $inputid = hsc($form->get_name() . '_' . $element['name']);
        $linktext = isset($element['expandtext']) ? hsc($element['expandtext']) : get_string('changepassword');
        $html = '<a href="" ' . "onclick=\"" . "addElementClass('{$inputid}_expand', 'hidden'); " . "jQuery('#{$inputid}').attr('name', '{$element['name']}');" . "removeElementClass('{$inputid}', 'hidden'); " . "return false;" . "\" id=\"{$inputid}_expand\">" . $linktext . '</a>';
        $element['class'] .= ' hidden';
        // This password input starts out invisible, and with a placeholder name (so that
        // it won't be processed by the form). When you click the link, it becomes visible
        // and gains its real name.
        // TODO: Non-JS version.
        return $html . '<input type="password" name="' . hsc($element['name'] . '_placeholder') . '" ' . $form->element_attributes($element, array('name')) . ' value="">';
    }
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:27,代码来源:passwordnoread.php

示例7: pieform_element_checkbox

/**
 * Provides a basic checkbox input.
 *
 * @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_checkbox(Pieform $form, $element)
{
    /*{{{*/
    $checked = false;
    if (isset($element['rules']['required'])) {
        throw new PieformException("For pieform_element_checkbox, 'required' is not allowed as a rule. Radio should be used instead.");
    }
    if (!empty($element['value'])) {
        $checked = true;
    }
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    if ($form->is_submitted() && isset($global[$element['name']])) {
        $checked = true;
    } else {
        if (!$form->is_submitted() && !empty($element['defaultvalue'])) {
            $checked = true;
        } else {
            if (!empty($element['readonly']) && !empty($element['defaultvalue'])) {
                $checked = true;
            }
        }
    }
    $arialabel = '';
    if (!empty($element['arialabel'])) {
        $arialabel = ' aria-label="' . Pieform::hsc($element['title']) . '"';
    }
    return '<input type="checkbox"' . $form->element_attributes($element) . $arialabel . ($checked ? ' checked="checked"' : '') . '>';
}
开发者ID:rboyatt,项目名称:mahara,代码行数:35,代码来源:checkbox.php

示例8: pieform_element_trafficlights

/**
 * Renders a set (red, yellow, green) of radio buttons with corresponding background colors as in traffic lights
 *
 * @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_trafficlights(Pieform $form, $element)
{
    /*{{{*/
    $global = $form->get_property('method') == 'get' ? $_GET : $_POST;
    $submitted = $form->is_submitted();
    if ($submitted && isset($global[$element['name']])) {
        $value = $global[$element['name']];
    }
    $result = '';
    if (!isset($element['options'])) {
        $element['options'] = array(array('value' => '0', 'title' => 'r'), array('value' => '1', 'title' => 'y'), array('value' => '2', 'title' => 'g'));
    }
    $result .= "<span style='display:block;border:0px;padding-bottom:4px;width:70px !important;'>";
    $colors = array('r' => '#FF8080', 'y' => '#FFEB80', 'g' => '#80B280');
    $borders = array('r' => 'border-top:1px solid #000000;border-left:1px solid #000000;border-bottom:1px solid #000000;', 'y' => 'border-top:1px solid #000000;border-bottom:1px solid #000000', 'g' => 'border-top:1px solid #000000;border-right:1px solid #000000;border-bottom:1px solid #000000;');
    foreach ($element['options'] as $e) {
        $checked = $form->get_value($element) === $e['value'] && !is_null($form->get_value($element));
        if ($e['value'] == null) {
            $checked = false;
        }
        $result .= '<span style="' . $borders[$e['title']] . ';padding-bottom:4px;background-color:' . $colors[$e['title']] . '"><input type="radio" value="' . $e['value'] . '" ' . $form->element_attributes($element) . ($checked ? ' checked="checked"' : '') . ' style="vertical-align:top"></span>';
    }
    $result .= "</span>";
    $result .= '<div class="cl"></div>';
    return $result;
}
开发者ID:gbleydon,项目名称:mahara-survey,代码行数:33,代码来源:trafficlights.php

示例9: pieform_element_submit

/**
 * Renders a submit button
 *
 * @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_submit(Pieform $form, $element)
{
    /*{{{*/
    if (isset($element['confirm'])) {
        $element['onclick'] = 'return confirm(' . json_encode($element['confirm']) . ');';
    }
    return '<input type="submit"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">';
}
开发者ID:Br3nda,项目名称:mahara,代码行数:15,代码来源:submit.php

示例10: pieform_element_button

/**
 * Renders an <input type="button"> element.
 *
 * The element must have the 'value' field set.
 *
 * @param Pieform $form    The form to render the element for
 * @param array   $element The element to render
 * @return string          The HTML for the element
 * @todo rename to inputbutton
 */
function pieform_element_button(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value'])) {
        throw new PieformException('Button elements must have a value');
    }
    return '<input type="button"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($element['value']) . '">';
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:18,代码来源:button.php

示例11: pieform_element_file

/**
 * Renders a basic HTML <input type="file"> element.
 *
 * @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_file(Pieform $form, $element)
{
    /*{{{*/
    $result = '';
    if (isset($element['maxfilesize']) && is_int($element['maxfilesize'])) {
        $result = '<input type="hidden" name="MAX_FILE_SIZE" value="' . $element['maxfilesize'] . '"/>';
    }
    $result .= '<input type="file"' . $form->element_attributes($element) . '>';
    return $result;
}
开发者ID:richardmansfield,项目名称:richardms-mahara,代码行数:17,代码来源:file.php

示例12: pieform_element_image

/**
 * Renders an <input type="image"> button
 *
 * @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_image(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['src'])) {
        throw new PieformException('"image" elements must have a "src" for the image');
    }
    if (!isset($element['value'])) {
        $element['value'] = true;
    }
    return '<input type="image" src="' . Pieform::hsc($element['src']) . '"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">';
}
开发者ID:Br3nda,项目名称:mahara,代码行数:18,代码来源:image.php

示例13: pieform_element_radio

/**
 * Renders a set of radio buttons for a form
 *
 * @param Pieform $form  The form to render the element for
 * @param array $element The element to render. In addition to the standard Pieform
 *                       element attributes, it can also take the following optional
 *                       attributes:
 *                       - separator: The HTML string that should separate the radio
 *                         buttons (defaults to \n, always has \n appended to it)
 *                       - rowsize: How many radio buttons to print per row (defaults to 1)
 *                       - nolabels: Don't print the labels next to the individual radio buttons.
 * @return string           The HTML for the element
 */
function pieform_element_radio(Pieform $form, $element)
{
    if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) {
        throw new PieformException('Radio elements should have at least one option');
    }
    $result = '';
    $form_value = $form->get_value($element);
    $id = $element['id'];
    $separator = "\n";
    if (isset($element['separator'])) {
        $separator = $element['separator'] . $separator;
    }
    $rowsize = isset($element['rowsize']) ? (int) $element['rowsize'] : 1;
    $nolabels = isset($element['nolabels']) ? $element['nolabels'] : false;
    $classname = '';
    if (!empty($element['hiddenlabels'])) {
        $classname = ' class="accessible-hidden"';
    }
    $titletext = '';
    if (!empty($element['title'])) {
        $titletext = '<span class="accessible-hidden">' . Pieform::hsc($element['title']) . ': </span>';
    }
    $i = 0;
    foreach ($element['options'] as $value => $data) {
        $idsuffix = substr(md5(microtime()), 0, 4);
        $baseid = $element['id'];
        $element['id'] = $uid = $id . $idsuffix;
        if (is_array($data)) {
            $text = $data['text'];
            $description = isset($data['description']) ? $data['description'] : '';
        } else {
            $text = $data;
            $description = '';
        }
        $attributes = $form->element_attributes($element);
        $attributes = preg_replace("/aria-describedby=\"[^\"]*{$baseid}{$idsuffix}_description\\s*[^\"]*\"/", 'aria-describedby="$1_description"', $attributes);
        $result .= '<div class="radio">';
        $result .= '<input type="radio"' . $attributes . ' value="' . Pieform::hsc($value) . '"' . ($form_value == $value ? ' checked="checked"' : '') . '>';
        if (!$nolabels) {
            $result .= ' <label for="' . $form->get_name() . '_' . $uid . '"' . $classname . '>' . $titletext . Pieform::hsc($text) . "</label>" . ($description != '' ? '<div class="description">' . $description . '</div>' : '');
        }
        $result .= '</div>';
        $i++;
        if ($rowsize <= 1 || $i % $rowsize == 0) {
            $result .= $separator;
        }
    }
    // If there was a separator printed on the end, then remove it
    if ($rowsize <= 1 || $i % $rowsize == 0) {
        $result = substr($result, 0, -strlen($separator));
    }
    return $result;
}
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:66,代码来源:radio.php

示例14: pieform_element_weight

/**
 * Provides a control that allows the user to input where in a list they want 
 * to put something. Handy for indicating the order of some objects.
 *
 * @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_weight(Pieform $form, $element)
{
    pieform_element_weight_validate_element($element);
    $default = isset($element['defaultvalue']) ? intval($element['defaultvalue']) : 0;
    $result = '<input type="radio"' . $form->element_attributes($element) . ' value="0"';
    if ($default == 0) {
        $result .= ' checked="checked"';
    }
    $result .= '>';
    $i = 0;
    foreach ($element['existing'] as $existing) {
        $i++;
        $result .= "<br>" . Pieform::hsc($existing['title']);
        $result .= "<br><input type=\"radio\"" . $form->element_attributes($element) . " value=\"{$i}\"";
        if ($i == $default) {
            $result .= ' checked="checked"';
        }
        $result .= '>';
    }
    return $result;
    return '<input type="text"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">';
}
开发者ID:Br3nda,项目名称:mahara,代码行数:30,代码来源:weight.php

示例15: pieform_element_cancel

/**
 * Renders a "cancel" button. Custom buttons are rendered nearly the same as
 * normal submit buttons, only their name is changed (for use by the Pieform
 * class internally).
 *
 * @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_cancel(Pieform $form, $element)
{
    /*{{{*/
    if (!isset($element['value'])) {
        throw new PieformException('Cancel elements must have a value');
    }
    if (isset($element['confirm'])) {
        $element['onclick'] = 'return confirm(' . json_encode($element['confirm']) . ');';
    }
    $attributes = $form->element_attributes($element);
    $attributes = preg_replace('/name="(.*)"/', 'name="cancel_$1"', $attributes);
    $attributes = preg_replace('/id="(.*)"/', 'id="cancel_$1"', $attributes);
    return '<input type="submit"' . $attributes . ' value="' . Pieform::hsc($element['value']) . '">';
}
开发者ID:Br3nda,项目名称:mahara,代码行数:23,代码来源:cancel.php


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