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; }
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; }
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; }
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; }
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; }
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; }
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; }
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"; }
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; }
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; }
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; }
/** * 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; }
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; }
/** * 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; }
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); }
function form_fieldset($legend_text = '', $attributes = []) { $fieldset = '<fieldset'; $fieldset .= _attributes_to_string($attributes, false); $fieldset .= ">\n"; if ($legend_text != '') { $fieldset .= "<legend>{$legend_text}</legend>\n"; } return $fieldset; }
function renderCrFormFields($form) { $CI =& get_instance(); $aFields = array(); $formErrors = array_keys(validation_array_errors()); foreach ($form['fields'] as $name => $field) { $hasError = null; if (in_array($name, $formErrors)) { $hasError = 'has-error'; } $properties = array('name' => $name, 'value' => element('value', $field), 'class' => 'form-control'); if (element('disabled', $field) == true) { $properties += array('disabled' => 'disabled'); } if (element('placeholder', $field) != '') { $properties += array('placeholder' => $field['placeholder']); } $sField = ' <fieldset class="form-group ' . $hasError . '"> ' . form_label(element('label', $field), null, array('class' => 'col-xs-12 col-sm-3 col-md-3 col-lg-3 control-label')) . ' <div class="col-xs-12 col-sm-9 col-md-9 col-lg-9"> %s </div> </fieldset>'; switch ($field['type']) { case 'hidden': $aFields[] = form_hidden($name, $field['value']); break; case 'text': case 'numeric': case 'typeahead': if ($field['type'] == 'typeahead') { unset($properties['value']); } $aFields[] = sprintf($sField, form_input($properties)); break; case 'date': case 'datetime': $aFields[] = sprintf($sField, '<div class="input-group" style="width:1px"> ' . form_input(array('name' => $name, 'value' => element('value', $field), 'class' => 'form-control', 'size' => $field['type'] == 'datetime' ? 18 : 9, 'placeholder' => lang('DATE_FORMAT') . ($field['type'] == 'datetime' ? ' hh:mm:ss' : ''))) . ' <span class="input-group-addon"><i class="glyphicon glyphicon-remove fa fa-times"></i></span> <span class="input-group-addon"><i class="glyphicon glyphicon-th icon-th fa fa-th"></i></span> </div>'); break; case 'password': $aFields[] = sprintf($sField, form_password(array('name' => $name, 'value' => element('value', $field), 'class' => 'form-control'))); break; case 'textarea': $aFields[] = sprintf($sField, form_textarea($name, element('value', $field), 'class="form-control"')); break; case 'dropdown': $source = element('source', $field, array()); $source = sourceToDropdown($source, element('appendNullOption', $field)); if (element('multiple', $field) == true) { $properties += array('multiple' => 'multiple'); } $aFields[] = sprintf($sField, form_dropdown($name, $source, element('value', $field, null), _attributes_to_string($properties))); break; case 'groupCheckBox': $showId = element('showId', $field, false); $sTmp = '<ul class="groupCheckBox" name="' . $name . '"> <li><input type="text" style="display:none" /> </li>'; foreach ($field['source'] as $item) { $sTmp .= '<li> <div class="checkbox"> <label>' . form_checkbox(null, $item['id'], in_array($item['id'], $field['value'])) . $item['text'] . ($showId == true ? ' - ' . $item['id'] : '') . ' </label> </div> </li>'; } $sTmp .= '</ul>'; $aFields[] = sprintf($sField, $sTmp); break; case 'checkbox': $className = ''; if (element('hideOffset', $field) == true) { $className = ' hide '; } $aFields[] = ' <fieldset class="form-group"> <div class="' . $className . ' hidden-xs col-sm-3 col-md-3 col-lg-3 "> </div> <div class="col-xs-12 col-sm-9 col-md-9 col-lg-9 "> <div class="checkbox" > <label> ' . form_checkbox($name, 'on', $field['checked']) . ' ' . element('label', $field) . ' </label> </div> </div> </fieldset>'; break; case 'gallery': $aFields[] = sprintf($sField, ' <div id="' . $name . '" data-toggle="modal-gallery" data-target="#modal-gallery" class="gallery well" > <button type="button" class="btn btn-success btn-sm btnEditPhotos fileinput-button"> <i class="fa fa-picture-o" ></i> ' . lang('Edit pictures') . ' </button> <div class="thumbnails" ></div> </div> '); break; case 'subform': $aFields[] = sprintf($sField, ' <div name="' . $name . '" class="subform "> <div class="alert alert-warning"> <i class="fa fa-spinner fa-spin fa-lg"></i> <small>' . lang('loading ...') . '</small> </div> </div> '); break; case 'tree': $aFields[] = '<fieldset class="form-group tree">' . renderCrFormTree($field['source'], $field['value']) . '</fieldset>'; break; case 'link': $sField = ' <fieldset class="form-group" > ' . form_label('', null, array('class' => 'hidden-xs col-sm-3 col-md-3 col-lg-3 control-label')) . ' <div class="col-xs-12 col-sm-9 col-md-9 col-lg-9"> %s </div> </fieldset>'; $aFields[] = sprintf($sField, anchor($field['value'], $field['label'])); break; case 'raty': $aFields[] = sprintf($sField, '<div class="raty" name="' . $name . '" />'); break; case 'upload': $aFields[] = sprintf($sField, ' <div name="' . $name . '"> </div> '); break; case 'html': $aFields[] = $field['value']; break; } } return $aFields; }
private function hidden($name, $options) { $options['name'] = $this->multi($name); $options['id'] = $this->id($this->multi($name)); $options['value'] = $this->form_validation->set_value($this->multi($name), $this->values($name)); return '<input type="hidden"' . _attributes_to_string($options) . ' />'; }
/** * a Tooltip using dojo */ function tooltip($NAME = '', $value = '', $attr = array()) { add_dojo("dijit.Tooltip"); $attr = $this->attribute($attr, 'position', 'below', FALSE); $attr = _attributes_to_string($attr); return "<div dojoType=\"dijit.Tooltip\" connectId=\"{$NAME}\" {$attr}>{$value}</div>"; }
/** * Fieldset Tag * * Used to produce <fieldset><legend>text</legend>. To close fieldset * use form_fieldset_close() * * @param string The legend text * @param array Additional attributes * @return string */ function form_fieldset($legend_text = '', $attributes = array()) { $fieldset = '<fieldset' . _attributes_to_string($attributes) . ">\n"; if ($legend_text !== '') { return $fieldset . '<legend>' . $legend_text . "</legend>\n"; } return $fieldset; }
function form_open($path = array(), $attributes = '', $hidden = array(), $use_validation_engine = TRUE) { // default form method is post if (is_array($attributes) && !isset($attributes['method'])) { $attributes['method'] = 'post'; } else { if (is_string($attributes) && stripos($attributes, 'method=') === FALSE) { $attributes .= ' method="post"'; } } if (is_array($path) || !preg_match('#^(\\w+:/)?/#i', $path)) { extract(get_link_to($path, array(), TRUE)); if ($context == 'back') { // if method is get, then page is a hidden input parameter // otherwise, it must be a Query String parameter in the form action if (is_array($attributes) && strtolower($attributes['method']) == 'get' || stripos($attributes, 'method="get"') !== FALSE) { $form_action = $host; $hidden = array_merge($hidden, array('page' => $page)); } else { $form_action = $host . '?page=' . $page; } // when app is null, $page does not include the parts of the CI path // spec that tell CI what to execute... so we include them as hidden // parameters if (!$app) { $hidden = array_merge($hidden, array('a' => $application, 'c' => $controller, 'm' => $action, 'd' => $directory)); } } else { // on the front-end, $url always has everything it needs to be the form action... $form_action = $url; } } else { $form_action = $path; } $form = $form_action ? '<form action="' . $form_action . '"' : '<form'; // generate a random id, if one is not defined (to support the validation engine) $form_id = md5(uniqid() . $form_action . time()); if ($use_validation_engine) { if (is_array($attributes)) { if (!isset($attributes['id'])) { $attributes['id'] = $form_id; } else { $form_id = $attributes['id']; } } else { $matches = array(); if (!preg_match('#id="([^"]+)?"#i', $attributes, $matches)) { $attributes .= ' id="' . $form_id . '"'; } else { // defined $form_id = $matches[1]; } } } $form .= _attributes_to_string($attributes, TRUE); $form .= '>'; if ($use_validation_engine) { // make sure that our localization helper has been loaded $CI =& get_instance(); if ($CI) { $CI->load->helper('localization'); $locale = substr(locale(), 0, 2); } else { $locale = 'en'; } wp_enqueue_script("jquery-ve-{$locale}", resource("/js/jquery.ve-{$locale}.js"), array('jquery')); wp_enqueue_script('jquery-ve', resource('/js/jquery.ve.js'), array("jquery-ve-{$locale}")); wp_enqueue_style('jquery-ve', resource('/css/ve.jquery.css')); $id = $attributes['id']; $form .= "\n<script type=\"text/javascript\"> jQuery(function() { jQuery('#{$form_id}').validationEngine(); }); </script>"; } wp_enqueue_script('wpci-admin', resource('/js/admin.js'), array('jquery')); if (is_array($hidden) and count($hidden) > 0) { $form .= form_hidden($hidden); } return $form; }
function form_fieldset($legend_text = '', $attributes = array()) { $fieldset = "<fieldset"; $fieldset .= _attributes_to_string($attributes, FALSE); $fieldset .= ">\n"; if ($legend_text != '') { $fieldset .= "<legend>{$legend_text}</legend>\n"; } return $fieldset; }
/** * create a dojo tooltip an associate it to * another HTML element * * @param string $NAME HTML element ID to associate the tooltip to * @param string $value HTML content of teh tooltip * @param array/object/string $attr attributes to be added to the element * @return string the HTML string of the tooltip */ public function tooltip($NAME = '', $value = '', $attr = array()) { theme_add('dijit.Tooltip'); $this->attribute($attr, 'position', 'below', FALSE); $attr = _attributes_to_string($attr); return '<div dojoType="dijit.Tooltip" connectId="' . $NAME . '" ' . $attr . '>' . $value . '</div>'; }