From ea41c8aa1951216b6a9ccc99832d69d2b41c5ead Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 26 Feb 2014 18:31:02 +0200 Subject: Don't use error suppression on realpath() + style adjustments --- system/helpers/form_helper.php | 59 ++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 22 deletions(-) (limited to 'system/helpers/form_helper.php') 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 = '
\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 '\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 '\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 '\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']; -- cgit v1.2.3-24-g4f1b