本文整理汇总了PHP中FormHelper::cleanHtmlId方法的典型用法代码示例。如果您正苦于以下问题:PHP FormHelper::cleanHtmlId方法的具体用法?PHP FormHelper::cleanHtmlId怎么用?PHP FormHelper::cleanHtmlId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormHelper
的用法示例。
在下文中一共展示了FormHelper::cleanHtmlId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderTabStart
/**
* Renders an opening tab div
*
* @param string $title The tab title
* @param string $id tab id (optional). Generated from $title if empty.
*
* @return string
*/
function renderTabStart($title, $id = '')
{
if (empty($id)) {
$id = 'tab-' . $title;
}
$id = FormHelper::cleanHtmlId($id);
if (isset($this->tabs[$id])) {
trigger_error('Warning: id "' . $id . '" has already been used as tab identifier.', E_USER_WARNING);
} else {
$this->tabs[$id] = $title;
}
return '<div id="' . $id . '">';
}
示例2: input
/**
* Renders a form input field
*
* The attributes parameter accepts any html properties plus the following:
* - "label": set this value to wrap the input field into a label with the given value in front of the input field.
* - "help": Set to display a (help) text underneith the field.
*
* @static
* @access public
*
* @param string $type The type of the input field. (E.g. "text" or "hidden").
* @param string $name The name of the input field.
* @param string $value The value of the input field.
* @param array $attributes Array of (html) attributes.
*
* @return string Html rendered form element.
*/
static function input($type, $name, $value, $attributes = array())
{
$valid_types = array('text', 'hidden', 'password', 'submit', 'reset');
if (!in_array($type, $valid_types)) {
return '[Only types "' . join('", "', $valid_types) . '" are allowed in FormHelper::input()]';
}
if ($type == 'text' && isset($attributes['rows']) && intval($attributes['rows']) > 0) {
$tag = 'textarea';
$attributes['rows'] = intval($attributes['rows']);
} else {
$tag = 'input';
$attributes['type'] = $type;
$attributes['value'] = $value;
}
$attributes['id'] = !empty($attributes['id']) ? $attributes['id'] : $name;
$attributes['id'] = FormHelper::cleanHtmlId($attributes['id']);
$attributes['name'] = $name;
$label = '';
if (isset($attributes['label'])) {
$label = $attributes['label'] . ' ';
unset($attributes['label']);
}
$help = '';
if (isset($attributes['help'])) {
$help = $attributes['help'] . ' ';
unset($attributes['help']);
}
$attr = FormHelper::buildHtmlAttributes($attributes);
$html = '<' . $tag . $attr;
if ($tag == 'textarea') {
$html .= '>';
$html .= htmlspecialchars($value);
$html .= '</' . $tag . '>';
} else {
$html .= ' />';
}
if (!empty($label)) {
$html = '<label>' . $label . $html . '</label>';
}
if (!empty($help)) {
$html .= $help;
}
return $html;
}