本文整理汇总了PHP中_attributes_to_string函数的典型用法代码示例。如果您正苦于以下问题:PHP _attributes_to_string函数的具体用法?PHP _attributes_to_string怎么用?PHP _attributes_to_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_attributes_to_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: form_open
function form_open($action = '', $attributes = '', $hidden = array())
{
$CI =& get_instance();
$charset = strtolower($CI->config->item('charset'));
if ($attributes == '') {
$attributes = 'method="post" accept-charset="' . $charset . '"';
} else {
if (is_string($attributes)) {
if (strpos('accept-charset=', $attributes) === FALSE) {
$attributes .= ' accept-charset="' . $charset . '"';
}
} elseif (is_object($attributes) or is_array($attributes)) {
$attributes = (array) $attributes;
if (!in_array('accept-charset', $attributes)) {
$attributes['accept-charset'] = $charset;
}
}
}
$action = strpos($action, '://') === FALSE ? $CI->config->site_url($action) : $action;
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
if (is_array($hidden) and count($hidden) > 0) {
$form .= form_hidden($hidden);
}
return $form;
}
示例2: form_open
function form_open($action = '', $attributes = '', $hidden = array())
{
$ING =& get_instance();
$ING->load->helper('url');
if ($attributes == '') {
$attributes = 'method="post"';
}
// If an action is not a full URL then turn it into one
if ($action && strpos($action, '://') === FALSE) {
$action = site_url($action);
}
// If no action is provided then set to the current url
$action or $action = current_url();
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
if (config_item('csrf_protection') === TRUE and !(strpos($action, base_url()) === FALSE or strpos($form, 'method="get"'))) {
$hidden[$ING->security->get_csrf_token_name()] = $ING->security->get_csrf_hash();
}
if (is_array($hidden) and count($hidden) > 0) {
$form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
}
return $form;
}
示例3: form_open
function form_open($action = '', $attributes = array(), $hidden = array())
{
$CI =& get_instance();
// If no action is provided then set to the current url
if (!$action) {
$action = current_url($action);
} elseif (strpos($action, '://') === FALSE) {
$action = if_secure_site_url($action);
}
$attributes = _attributes_to_string($attributes);
if (stripos($attributes, 'method=') === FALSE) {
$attributes .= ' method="post"';
}
if (stripos($attributes, 'accept-charset=') === FALSE) {
$attributes .= ' accept-charset="' . strtolower(config_item('charset')) . '"';
}
$form = '<form action="' . $action . '"' . $attributes . ">\n";
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
if ($CI->config->item('csrf_protection') === TRUE && strpos($action, if_secure_base_url()) !== FALSE && !stripos($form, 'method="get"')) {
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
// Add MY CSRF token if MY CSRF library is loaded
if ($CI->load->is_loaded('tokens') && strpos($action, if_secure_base_url()) !== FALSE && !stripos($form, 'method="get"')) {
$hidden[$CI->tokens->name] = $CI->tokens->token();
}
if (is_array($hidden)) {
foreach ($hidden as $name => $value) {
$form .= '<input type="hidden" name="' . $name . '" value="' . html_escape($value) . '" style="display:none;" />' . "\n";
}
}
return $form;
}
示例4: form_open
function form_open($action = '', $attributes = '', $hidden = array())
{
$_ci = & get_instance();
$_ci->load->library('form_validation');
if ($attributes == '')
{
$attributes = 'method="post"';
}
$action = ( strpos($action, '://') === FALSE) ? $_ci->config->site_url($action) : $action;
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
if ($_ci->form_validation->has_nonce())
{
$value = set_value('nonce');
if ($value == '')
{
$value = $_ci->form_validation->create_nonce();
}
$hidden['nonce'] = set_value('nonce', $value);
}
if (is_array($hidden) && count($hidden) > 0)
{
$form .= form_hidden($hidden);
}
return $form;
}
示例5: form_open
function form_open($action = '', $attributes = '', $hidden = array())
{
$CI =& get_instance();
if ($attributes == '') {
$attributes = 'method="post"';
}
// If an action is not a full URL then turn it into one
if ($action && strpos($action, '://') === FALSE) {
$action = $CI->config->site_url($action);
}
// If no action is provided then set to the current url
$action or $action = $CI->config->site_url($CI->uri->uri_string());
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
$_base_url = $CI->config->base_url();
$_secure_base_url = $CI->config->secure_base_url();
if ($CI->config->item('csrf_protection') === TRUE and !(strpos($action, $_base_url) === FALSE or strpos($form, 'method="get"'))) {
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
// If the secure_base_url is different, then do a check for that domain/url too.
if ($_base_url != $_secure_base_url) {
if ($CI->config->item('csrf_protection') === TRUE and !(strpos($action, $_secure_base_url) === FALSE or strpos($form, 'method="get"'))) {
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
}
// Render any hidden fields
if (is_array($hidden) and count($hidden) > 0) {
$form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
}
return $form;
}
示例6: form_open
function form_open($a = '', $b = '', $c = array())
{
if ($b == '') {
$b = 'method="post"';
}
$d = '<form action="' . $a . '"';
$d .= _attributes_to_string($b, TRUE);
$d .= '>';
if (is_array($c) and count($c) > 0) {
$d .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($c));
}
return $d;
}
示例7: form_open
function form_open($action = '', $attributes = '', $hidden = array())
{
if ($attributes == '') {
$attributes = 'method="post"';
}
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
if (is_array($hidden) and count($hidden) > 0) {
$form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
}
return $form;
}
示例8: chainned_dropdown
function chainned_dropdown($data = '', $options = array(), $selected = array(), $extra = '', $extra_options = '')
{
$defaults = array();
if (is_array($data)) {
if (isset($data['selected'])) {
$selected = $data['selected'];
unset($data['selected']);
// select tags don't have a selected attribute
}
if (isset($data['options'])) {
$options = $data['options'];
unset($data['options']);
// select tags don't use an options attribute
}
} else {
$defaults = array('name' => $data);
}
is_array($selected) or $selected = array($selected);
is_array($options) or $options = array($options);
// If no selected state was submitted we will attempt to set it automatically
if (empty($selected)) {
if (is_array($data)) {
if (isset($data['name'], $_POST[$data['name']])) {
$selected = array($_POST[$data['name']]);
}
} elseif (isset($_POST[$data])) {
$selected = array($_POST[$data]);
}
}
$extra = _attributes_to_string($extra);
$extra_options = _attributes_to_string($extra_options);
$multiple = count($selected) > 1 && stripos($extra, 'multiple') === FALSE ? ' multiple="multiple"' : '';
$form = '<select ' . rtrim(_parse_form_attributes($data, $defaults)) . $extra . $multiple . ">\n";
foreach ($options as $key => $val) {
$key = (string) $key;
if (is_array($val)) {
if (empty($val)) {
continue;
}
$form .= '<optgroup label="' . $key . "\">\n";
foreach ($val as $optgroup_key => $optgroup_val) {
$sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : '';
$form .= '<option ' . $extra_options . ' value="' . html_escape($optgroup_key) . '"' . $sel . '>' . (string) $optgroup_val . "</option>\n";
}
$form .= "</optgroup>\n";
} else {
$form .= '<option ' . $extra_options . ' value="' . html_escape($key) . '"' . (in_array($key, $selected) ? ' selected="selected"' : '') . '>' . (string) $val . "</option>\n";
}
}
return $form . "</select>\n";
}
示例9: open
public function open($action = '', $attributes = array(), $attributes_table = array())
{
static $form;
$attributes = _attributes_to_string($attributes);
if (stripos($attributes, 'method=') === FALSE) {
$attributes .= ' method="post"';
}
$attributes = _attributes_to_string($attributes);
$attributes_table = _attributes_to_string($attributes_table);
$form .= '<form action="' . $action . '"' . $attributes . '>';
$form .= '<table class="form-table"' . $attributes_table . '>';
$form .= '<tbody>';
echo $form;
}
示例10: secure_form_open
function secure_form_open($action = '', $attributes = '', $hidden = array())
{
$CI =& get_instance();
if ($attributes == '') {
$attributes = 'method="post"';
}
$action = strpos($action, '://') === FALSE ? $CI->config->secure_site_url($action) : $action;
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
if (is_array($hidden) and count($hidden) > 0) {
$form .= form_hidden($hidden);
}
return $form;
}
示例11: secure_form_open
function secure_form_open($action = '', $attributes = '', $hidden = array())
{
$CI =& get_instance();
if ($attributes == '') {
$attributes = 'method="post"';
}
$action = strpos($action, '://') === FALSE ? $CI->config->secure_site_url($action) : $action;
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
// CSRF
if ($CI->config->item('csrf_protection') === TRUE) {
$hidden[$CI->security->csrf_token_name] = $CI->security->csrf_hash;
}
if (is_array($hidden) and count($hidden) > 0) {
$form .= sprintf("\n<div class=\"hidden\">%s</div>", form_hidden($hidden));
}
return $form;
}
示例12: form_open
/**
* Form Open
*
* Create the form open tag as well as any hidden inputs. Also implements CSRF.
*
* @param string The action attribute
* @param string A string of extra attributes
* @param array An array of hidden elements
* @param bool If CSRF should be enabled
* @return string The form element and any hidden inputs
*/
function form_open($action = '', $attributes = '', $hidden = array(), $csrf_enabled = TRUE)
{
$_ci =& get_instance();
$_ci->load->library('form_validation');
if ($attributes == '') {
$attributes = 'method="post"';
}
$action = strpos($action, '://') === FALSE ? $_ci->config->site_url($action) : $action;
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
if (is_array($hidden) && count($hidden) > 0) {
$form .= form_hidden($hidden);
}
if ($csrf_enabled) {
$form .= form_token();
}
return $form;
}
示例13: form_open
function form_open($action = '', $attributes = array(), $hidden = array())
{
$CI =& get_instance();
// Load URL helper for the site_url and base_url functions
$CI->load->helper('url');
// Set the link protocol to https if secure
$link_protocol = USE_SSL && is_https() ? 'https' : NULL;
// If no action is provided then set to the current url
if (!$action) {
$action = current_url($action);
if (is_https()) {
if (parse_url($action, PHP_URL_SCHEME) == 'http') {
$action = substr($action, 0, 4) . 's' . substr($action, 4);
}
}
$action = $_SERVER['QUERY_STRING'] ? $action . '?' . $_SERVER['QUERY_STRING'] : $action;
} elseif (strpos($action, '://') === FALSE) {
$action = site_url($action, $link_protocol);
}
$attributes = _attributes_to_string($attributes);
if (stripos($attributes, 'method=') === FALSE) {
$attributes .= ' method="post"';
}
if (stripos($attributes, 'accept-charset=') === FALSE) {
$attributes .= ' accept-charset="' . strtolower(config_item('charset')) . '"';
}
$form = '<form action="' . $action . '"' . $attributes . ">\n";
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
if ($CI->config->item('csrf_protection') === TRUE && strpos($action, base_url('', $link_protocol)) !== FALSE && !stripos($form, 'method="get"')) {
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
// Add MY CSRF token if MY CSRF library is loaded
if ($CI->load->is_loaded('tokens') && strpos($action, base_url('', $link_protocol)) !== FALSE && !stripos($form, 'method="get"')) {
$hidden[$CI->tokens->name] = $CI->tokens->token();
}
if (is_array($hidden)) {
foreach ($hidden as $name => $value) {
$form .= '<input type="hidden" name="' . $name . '" value="' . html_escape($value) . '" style="display:none;" />' . "\n";
}
}
return $form;
}
示例14: parse_html_attrs
/**
* Parsing html attributes,
* Actually CI has built-in _attributes_to_string() function, but I wonder
* It's belong to form_helper instead of html_helper. So I make it available
* in form helper as well. NOTICE: this function will fallback to default
* _attributes_to_string() if form_helper is loaded.
*
* @param mixed $attributes Attributes
* @return string
*/
function parse_html_attrs($attributes = null)
{
if (function_exists('_attributes_to_string')) {
return _attributes_to_string($attributes);
}
if (empty($attributes)) {
return '';
}
if (is_string($attributes)) {
return $attributes;
}
if (is_object($attributes)) {
$attributes = (array) $attributes;
}
if (is_array($attributes)) {
$atts = [];
foreach ($attributes as $key => $val) {
$atts[] = $key . '="' . html_escape($val) . '"';
}
return implode(' ', $atts);
}
return false;
}
示例15: form_open
function form_open($action = '', $attributes = '', $hidden = array())
{
$CI =& get_instance();
$name = $CI->controller . '-' . $CI->method;
if ($attributes == '') {
$attributes = 'method="post"';
}
if (is_string($attributes)) {
if (strpos($attributes, 'name=') === FALSE) {
$attributes .= ' name="' . $name . '"';
}
} else {
if (!isset($attributes['name'])) {
$attributes['name'] = $name;
}
}
// If an action is not a full URL then turn it into one
if ($action && strpos($action, '://') === FALSE) {
$action = $CI->config->site_url($action);
}
// If no action is provided then set to the current url
$action or $action = $CI->config->site_url($CI->uri->uri_string());
$form = '<form action="' . $action . '"';
$form .= _attributes_to_string($attributes, TRUE);
$form .= '>';
// Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
if ($CI->config->item('csrf_protection') === TRUE and !(strpos($action, $CI->config->site_url()) === FALSE or strpos($form, 'method="get"'))) {
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
if (is_array($hidden) and count($hidden) > 0) {
$form .= sprintf("<div style=\"display:none\">%s</div>", form_hidden($hidden));
}
return $form;
$CI =& get_instance();
return form_open($action, $attributes, $hidden);
}