summaryrefslogtreecommitdiffstats
path: root/system/helpers/form_helper.php
diff options
context:
space:
mode:
Diffstat (limited to 'system/helpers/form_helper.php')
-rw-r--r--system/helpers/form_helper.php59
1 files changed, 37 insertions, 22 deletions
diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php
index a724406f0..2592890cd 100644
--- a/system/helpers/form_helper.php
+++ b/system/helpers/form_helper.php
@@ -54,15 +54,15 @@ if ( ! function_exists('form_open'))
{
$CI =& get_instance();
- // If an action is not a full URL then turn it into one
- if ($action && strpos($action, '://') === FALSE)
+ // If no action is provided then set to the current url
+ if ( ! $action)
{
- $action = $CI->config->site_url($action);
+ $action = $CI->config->site_url($CI->uri->uri_string());
}
- elseif ( ! $action)
+ // If an action is not a full URL then turn it into one
+ elseif (strpos($action, '://') === FALSE)
{
- // If no action is provided then set to the current url
- $action = $CI->config->site_url($CI->uri->uri_string());
+ $action = $CI->config->site_url($action);
}
$attributes = _attributes_to_string($attributes);
@@ -80,7 +80,7 @@ if ( ! function_exists('form_open'))
$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, $CI->config->base_url()) === FALSE OR stripos($form, 'method="get"')))
+ if ($CI->config->item('csrf_protection') === TRUE && strpos($action, $CI->config->base_url()) !== FALSE && ! stripos($form, 'method="get"'))
{
$hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
}
@@ -153,6 +153,7 @@ if ( ! function_exists('form_hidden'))
{
form_hidden($key, $val, TRUE);
}
+
return $form;
}
@@ -187,7 +188,11 @@ if ( ! function_exists('form_input'))
*/
function form_input($data = '', $value = '', $extra = '')
{
- $defaults = array('type' => 'text', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
+ $defaults = array(
+ 'type' => 'text',
+ 'name' => is_array($data) ? '' : $data,
+ 'value' => $value
+ );
return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
}
@@ -209,11 +214,7 @@ if ( ! function_exists('form_password'))
*/
function form_password($data = '', $value = '', $extra = '')
{
- if ( ! is_array($data))
- {
- $data = array('name' => $data);
- }
-
+ is_array($data) OR $data = array('name' => $data);
$data['type'] = 'password';
return form_input($data, $value, $extra);
}
@@ -256,7 +257,11 @@ if ( ! function_exists('form_textarea'))
*/
function form_textarea($data = '', $value = '', $extra = '')
{
- $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'cols' => '40', 'rows' => '10');
+ $defaults = array(
+ 'name' => is_array($data) ? '' : $data,
+ 'cols' => '40',
+ 'rows' => '10'
+ );
if ( ! is_array($data) OR ! isset($data['value']))
{
@@ -434,11 +439,7 @@ if ( ! function_exists('form_radio'))
*/
function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
{
- if ( ! is_array($data))
- {
- $data = array('name' => $data);
- }
-
+ is_array($data) OR $data = array('name' => $data);
$data['type'] = 'radio';
return form_checkbox($data, $value, $checked, $extra);
}
@@ -458,7 +459,12 @@ if ( ! function_exists('form_submit'))
*/
function form_submit($data = '', $value = '', $extra = '')
{
- $defaults = array('type' => 'submit', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
+ $defaults = array(
+ 'type' => 'submit',
+ 'name' => is_array($data) ? '' : $data,
+ 'value' => $value
+ );
+
return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
}
}
@@ -477,7 +483,12 @@ if ( ! function_exists('form_reset'))
*/
function form_reset($data = '', $value = '', $extra = '')
{
- $defaults = array('type' => 'reset', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
+ $defaults = array(
+ 'type' => 'reset',
+ 'name' => is_array($data) ? '' : $data,
+ 'value' => $value
+ );
+
return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
}
}
@@ -496,7 +507,11 @@ if ( ! function_exists('form_button'))
*/
function form_button($data = '', $content = '', $extra = '')
{
- $defaults = array('name' => ( ! is_array($data) ? $data : ''), 'type' => 'button');
+ $defaults = array(
+ 'name' => is_array($data) ? '' : $data,
+ 'type' => 'button'
+ );
+
if (is_array($data) && isset($data['content']))
{
$content = $data['content'];