本文整理汇总了PHP中Smarty_Internal_Template::applyFieldValidation方法的典型用法代码示例。如果您正苦于以下问题:PHP Smarty_Internal_Template::applyFieldValidation方法的具体用法?PHP Smarty_Internal_Template::applyFieldValidation怎么用?PHP Smarty_Internal_Template::applyFieldValidation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Smarty_Internal_Template
的用法示例。
在下文中一共展示了Smarty_Internal_Template::applyFieldValidation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_textfield
/**
* Renders text field
*
* If you wish to use autocomplete on a text field an additional parameter needs to be passed:
*
* <code>
* autocomplete="controller=somecontroller field=fieldname"
* </code>
*
* The controller needs to implement an autoComplete method, which must return the AutoCompleteResponse
*
* @param array $params
* @param Smarty $smarty
* @return string
*
* @package application.helper.smarty.form
* @author Integry Systems
*/
function smarty_function_textfield($params, Smarty_Internal_Template $smarty)
{
if (empty($params['name'])) {
$params['name'] = $smarty->getTemplateVars('input_name');
}
$smarty->assign('last_fieldType', 'textfield');
$formParams = $smarty->_tag_stack[0][1];
$formHandler = $formParams['handle'];
$fieldName = $params['name'];
if (!$formHandler instanceof Form) {
throw new HelperException('Element must be placed in {form} block');
}
if (!isset($params['type'])) {
$params['type'] = 'text';
}
if (isset($params['ng_model'])) {
$params['ng-model'] = $params['ng_model'];
unset($params['ng_model']);
} else {
if (!empty($formParams['model'])) {
$params['ng-model'] = $formParams['model'] . '.' . $params['name'];
}
}
$params = $smarty->applyFieldValidation($params, $formHandler);
// Check permissions
if ($formParams['readonly']) {
$params['readonly'] = 'readonly';
}
$value = array_pop(array_filter(array(isset($params['value']) ? $params['value'] : '', isset($params['default']) ? $params['default'] : '', $formHandler->get($fieldName))));
unset($params['value'], $params['default']);
if (isset($params['autocomplete']) && $params['autocomplete'] != 'off' && empty($params['id'])) {
$params['id'] = uniqid();
}
if (!empty($params['placeholder'])) {
$params['placeholder'] = $smarty->getApplication()->translate($params['placeholder']);
}
if (isset($params['autocomplete']) && $params['autocomplete'] != 'off') {
$autocomplete = $params['autocomplete'];
$params['autocomplete'] = 'off';
}
$content = '<input';
$content = $smarty->appendParams($content, $params);
$content .= ' value="' . htmlspecialchars($value, ENT_QUOTES, 'UTF-8') . '"';
$content .= '/>';
$content = $smarty->formatControl($content, $params);
if (!empty($autocomplete)) {
$acparams = array();
foreach (explode(' ', $params['autocomplete']) as $param) {
list($p, $v) = explode('=', $param, 2);
$acparams[$p] = $v;
}
$url = $smarty->getApplication()->getRouter()->createURL(array('controller' => $acparams['controller'], 'action' => 'autoComplete', 'query' => 'field=' . $acparams['field']), true);
if (empty($acparams['field'])) {
$acparams['field'] = 'query';
}
/*
$content .= '<script type="text/javascript">
jQuery("#' . $params['id'] . '").typeahead({
source: function (query, process) {
return jQuery.get("' . $url . '", { ' . $acparams['field'] . ': query }, function (data) {
return process(jQuery.parseJSON(data));
});
}});
</script>';
*/
}
return $content;
}