本文整理匯總了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;
}