From 43e0fbb650d05466cd2568b8a2cc1c38849a6b52 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 26 Aug 2008 19:22:31 +0000 Subject: Added some new functions that work with the new form validation class --- system/helpers/form_helper.php | 335 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 321 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/helpers/form_helper.php b/system/helpers/form_helper.php index 0c74ac0ff..a96adb97d 100644 --- a/system/helpers/form_helper.php +++ b/system/helpers/form_helper.php @@ -53,7 +53,7 @@ if ( ! function_exists('form_open')) $form = '
'text', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -214,17 +214,17 @@ if ( ! function_exists('form_textarea')) { $defaults = array('name' => (( ! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12'); - if ( ! is_array($data) OR ! isset($data['value'])) + if ( ! is_array($data) OR ! isset($data['value'])) { $val = $value; } - else + else { $val = $data['value']; unset($data['value']); // textareas don't use the value attribute } - return ""; + return ""; } } @@ -248,6 +248,16 @@ if ( ! function_exists('form_dropdown')) { $selected = array($selected); } + + // If no selected state was submitted we will attempt to set it automatically + if (count($selected) === 0) + { + // If the form name appears in the $_POST array we have a winner! + if (isset($_POST[$name])) + { + $selected = array($_POST[$name]); + } + } if ($extra != '') $extra = ' '.$extra; @@ -312,7 +322,7 @@ if ( ! function_exists('form_checkbox')) unset($defaults['checked']); } - return ""; + return ""; } } @@ -359,7 +369,7 @@ if ( ! function_exists('form_submit')) { $defaults = array('type' => 'submit', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -380,7 +390,7 @@ if ( ! function_exists('form_reset')) { $defaults = array('type' => 'reset', 'name' => (( ! is_array($data)) ? $data : ''), 'value' => $value); - return ""; + return ""; } } @@ -407,7 +417,7 @@ if ( ! function_exists('form_button')) unset($data['content']); // content is not an attribute } - return ""; + return ""; } } @@ -466,7 +476,7 @@ if ( ! function_exists('form_fieldset')) { $fieldset = " $val) + { + $str[$key] = form_prep($val); + } + + return $str; + } + if ($str === '') { return ''; @@ -552,7 +573,256 @@ if ( ! function_exists('form_prep')) return $str; } } + +// ------------------------------------------------------------------------ + +/** + * Form Value + * + * Grabs a value from the POST array for the specified field so you can + * re-populate an input field or textarea. If Form Validation + * is active it retrieves the info from the validation class + * + * @access public + * @param string + * @return mixed + */ +if ( ! function_exists('set_value')) +{ + function set_value($field = '', $default = '') + { + if (FALSE === ($OBJ =& _get_validation_object())) + { + if ( ! isset($_POST[$field])) + { + return $default; + } + + return $_POST[$field]; + } + + return $OBJ->set_value($field, $default); + } +} + +// ------------------------------------------------------------------------ + +/** + * Set Select + * + * Let's you set the selected value of a