Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 1 | <?php |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 5 | * An open source application development framework for PHP |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 7 | * This content is released under the MIT License (MIT) |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 8 | * |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2015, British Columbia Institute of Technology |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 10 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 11 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 12 | * of this software and associated documentation files (the "Software"), to deal |
| 13 | * in the Software without restriction, including without limitation the rights |
| 14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 15 | * copies of the Software, and to permit persons to whom the Software is |
| 16 | * furnished to do so, subject to the following conditions: |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 17 | * |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 18 | * The above copyright notice and this permission notice shall be included in |
| 19 | * all copies or substantial portions of the Software. |
| 20 | * |
| 21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 27 | * THE SOFTWARE. |
| 28 | * |
| 29 | * @package CodeIgniter |
| 30 | * @author EllisLab Dev Team |
darwinel | 871754a | 2014-02-11 17:34:57 +0100 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) |
Andrey Andreev | fe9309d | 2015-01-09 17:48:58 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/) |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 33 | * @license http://opensource.org/licenses/MIT MIT License |
| 34 | * @link http://codeigniter.com |
| 35 | * @since Version 1.0.0 |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 36 | * @filesource |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | */ |
Andrey Andreev | c5536aa | 2012-11-01 17:33:58 +0200 | [diff] [blame] | 38 | defined('BASEPATH') OR exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 39 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 40 | /** |
| 41 | * CodeIgniter Form Helpers |
| 42 | * |
| 43 | * @package CodeIgniter |
| 44 | * @subpackage Helpers |
| 45 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 46 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 47 | * @link http://codeigniter.com/user_guide/helpers/form_helper.html |
| 48 | */ |
| 49 | |
| 50 | // ------------------------------------------------------------------------ |
| 51 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 52 | if ( ! function_exists('form_open')) |
| 53 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 54 | /** |
| 55 | * Form Declaration |
| 56 | * |
| 57 | * Creates the opening portion of the form. |
| 58 | * |
| 59 | * @param string the URI segments of the form destination |
| 60 | * @param array a key/value pair of attributes |
| 61 | * @param array a key/value pair hidden data |
| 62 | * @return string |
| 63 | */ |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 64 | function form_open($action = '', $attributes = array(), $hidden = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 65 | { |
| 66 | $CI =& get_instance(); |
| 67 | |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 68 | // If no action is provided then set to the current url |
| 69 | if ( ! $action) |
| 70 | { |
| 71 | $action = $CI->config->site_url($CI->uri->uri_string()); |
| 72 | } |
vlakoff | c4f9c62 | 2013-07-27 10:08:00 +0200 | [diff] [blame] | 73 | // If an action is not a full URL then turn it into one |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 74 | elseif (strpos($action, '://') === FALSE) |
vlakoff | c4f9c62 | 2013-07-27 10:08:00 +0200 | [diff] [blame] | 75 | { |
| 76 | $action = $CI->config->site_url($action); |
| 77 | } |
vlakoff | c4f9c62 | 2013-07-27 10:08:00 +0200 | [diff] [blame] | 78 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 79 | $attributes = _attributes_to_string($attributes); |
| 80 | |
| 81 | if (stripos($attributes, 'method=') === FALSE) |
Andrey Andreev | 122ca9b | 2013-07-26 18:16:26 +0300 | [diff] [blame] | 82 | { |
| 83 | $attributes .= ' method="post"'; |
| 84 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 85 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 86 | if (stripos($attributes, 'accept-charset=') === FALSE) |
| 87 | { |
| 88 | $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"'; |
| 89 | } |
| 90 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 91 | $form = '<form action="'.$action.'"'.$attributes.">\n"; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 92 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 93 | // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 94 | if ($CI->config->item('csrf_protection') === TRUE && strpos($action, $CI->config->base_url()) !== FALSE && ! stripos($form, 'method="get"')) |
Derek Allard | 958543a | 2010-07-22 14:10:26 -0400 | [diff] [blame] | 95 | { |
Greg Aker | 1f6f0ab | 2011-04-07 18:24:53 -0500 | [diff] [blame] | 96 | $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash(); |
Greg Aker | 28b425a | 2010-09-15 11:43:23 -0500 | [diff] [blame] | 97 | } |
| 98 | |
Andrey Andreev | 93b4e78 | 2014-03-04 17:48:21 +0200 | [diff] [blame] | 99 | if (is_array($hidden)) |
Greg Aker | 28b425a | 2010-09-15 11:43:23 -0500 | [diff] [blame] | 100 | { |
Andrey Andreev | 93b4e78 | 2014-03-04 17:48:21 +0200 | [diff] [blame] | 101 | foreach ($hidden as $name => $value) |
| 102 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 103 | $form .= '<input type="hidden" name="'.$name.'" value="'.html_escape($value).'" style="display:none;" />'."\n"; |
Andrey Andreev | 93b4e78 | 2014-03-04 17:48:21 +0200 | [diff] [blame] | 104 | } |
Derek Allard | 958543a | 2010-07-22 14:10:26 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 107 | return $form; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // ------------------------------------------------------------------------ |
| 112 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 113 | if ( ! function_exists('form_open_multipart')) |
| 114 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 115 | /** |
| 116 | * Form Declaration - Multipart type |
| 117 | * |
| 118 | * Creates the opening portion of the form, but with "multipart/form-data". |
| 119 | * |
| 120 | * @param string the URI segments of the form destination |
| 121 | * @param array a key/value pair of attributes |
| 122 | * @param array a key/value pair hidden data |
| 123 | * @return string |
| 124 | */ |
Ben Edmunds | 98963b3 | 2011-08-20 14:17:16 -0500 | [diff] [blame] | 125 | function form_open_multipart($action = '', $attributes = array(), $hidden = array()) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 126 | { |
Derek Allard | 33d4b6a | 2010-01-17 07:23:00 +0000 | [diff] [blame] | 127 | if (is_string($attributes)) |
| 128 | { |
| 129 | $attributes .= ' enctype="multipart/form-data"'; |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | $attributes['enctype'] = 'multipart/form-data'; |
| 134 | } |
| 135 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 136 | return form_open($action, $attributes, $hidden); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | // ------------------------------------------------------------------------ |
| 141 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 142 | if ( ! function_exists('form_hidden')) |
| 143 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 144 | /** |
| 145 | * Hidden Input Field |
| 146 | * |
| 147 | * Generates hidden fields. You can pass a simple key/value string or |
| 148 | * an associative array with multiple values. |
| 149 | * |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 150 | * @param mixed $name Field name |
| 151 | * @param string $value Field value |
| 152 | * @param bool $recursing |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 153 | * @return string |
| 154 | */ |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 155 | function form_hidden($name, $value = '', $recursing = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 156 | { |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 157 | static $form; |
| 158 | |
| 159 | if ($recursing === FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 160 | { |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 161 | $form = "\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 164 | if (is_array($name)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 165 | { |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 166 | foreach ($name as $key => $val) |
| 167 | { |
| 168 | form_hidden($key, $val, TRUE); |
| 169 | } |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 170 | |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 171 | return $form; |
| 172 | } |
| 173 | |
| 174 | if ( ! is_array($value)) |
| 175 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 176 | $form .= '<input type="hidden" name="'.$name.'" value="'.html_escape($value)."\" />\n"; |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 177 | } |
| 178 | else |
| 179 | { |
| 180 | foreach ($value as $k => $v) |
| 181 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 182 | $k = is_int($k) ? '' : $k; |
Robin Sowell | 57fe410 | 2009-03-26 18:58:46 +0000 | [diff] [blame] | 183 | form_hidden($name.'['.$k.']', $v, TRUE); |
| 184 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | return $form; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // ------------------------------------------------------------------------ |
| 192 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 193 | if ( ! function_exists('form_input')) |
| 194 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 195 | /** |
| 196 | * Text Input Field |
| 197 | * |
| 198 | * @param mixed |
| 199 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 200 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 201 | * @return string |
| 202 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 203 | function form_input($data = '', $value = '', $extra = '') |
| 204 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 205 | $defaults = array( |
| 206 | 'type' => 'text', |
| 207 | 'name' => is_array($data) ? '' : $data, |
| 208 | 'value' => $value |
| 209 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 210 | |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 211 | $extra = _attributes_to_string($extra); |
| 212 | |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 213 | return '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 214 | } |
| 215 | } |
| 216 | |
| 217 | // ------------------------------------------------------------------------ |
| 218 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 219 | if ( ! function_exists('form_password')) |
| 220 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 221 | /** |
| 222 | * Password Field |
| 223 | * |
| 224 | * Identical to the input function but adds the "password" type |
| 225 | * |
| 226 | * @param mixed |
| 227 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 228 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 229 | * @return string |
| 230 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 231 | function form_password($data = '', $value = '', $extra = '') |
| 232 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 233 | is_array($data) OR $data = array('name' => $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 234 | $data['type'] = 'password'; |
| 235 | return form_input($data, $value, $extra); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | // ------------------------------------------------------------------------ |
| 240 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 241 | if ( ! function_exists('form_upload')) |
| 242 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 243 | /** |
| 244 | * Upload Field |
| 245 | * |
| 246 | * Identical to the input function but adds the "file" type |
| 247 | * |
| 248 | * @param mixed |
| 249 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 250 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 251 | * @return string |
| 252 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 253 | function form_upload($data = '', $value = '', $extra = '') |
| 254 | { |
Bo-Yi Wu | 06ddcf0 | 2013-02-18 08:52:05 +0800 | [diff] [blame] | 255 | $defaults = array('type' => 'file', 'name' => ''); |
Andrey Andreev | 99ba3a2 | 2013-02-15 22:42:22 +0200 | [diff] [blame] | 256 | is_array($data) OR $data = array('name' => $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 257 | $data['type'] = 'file'; |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 258 | |
| 259 | $extra = _attributes_to_string($extra); |
| 260 | |
Andrey Andreev | 99ba3a2 | 2013-02-15 22:42:22 +0200 | [diff] [blame] | 261 | return '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
| 265 | // ------------------------------------------------------------------------ |
| 266 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 267 | if ( ! function_exists('form_textarea')) |
| 268 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 269 | /** |
| 270 | * Textarea field |
| 271 | * |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 272 | * @param mixed $data |
| 273 | * @param string $value |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 274 | * @param mixed $extra |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 275 | * @return string |
| 276 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 277 | function form_textarea($data = '', $value = '', $extra = '') |
| 278 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 279 | $defaults = array( |
| 280 | 'name' => is_array($data) ? '' : $data, |
| 281 | 'cols' => '40', |
| 282 | 'rows' => '10' |
| 283 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 284 | |
| 285 | if ( ! is_array($data) OR ! isset($data['value'])) |
| 286 | { |
| 287 | $val = $value; |
| 288 | } |
| 289 | else |
| 290 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 291 | $val = $data['value']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 292 | unset($data['value']); // textareas don't use the value attribute |
| 293 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 294 | |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 295 | $extra = _attributes_to_string($extra); |
| 296 | |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 297 | return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.html_escape($val)."</textarea>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | // ------------------------------------------------------------------------ |
| 302 | |
Derek Jones | 68788d5 | 2010-03-05 10:11:31 -0600 | [diff] [blame] | 303 | if ( ! function_exists('form_multiselect')) |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 304 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 305 | /** |
| 306 | * Multi-select menu |
| 307 | * |
| 308 | * @param string |
| 309 | * @param array |
| 310 | * @param mixed |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 311 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 312 | * @return string |
| 313 | */ |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 314 | function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') |
| 315 | { |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 316 | $extra = _attributes_to_string($extra); |
| 317 | |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 318 | if ( ! strpos($extra, 'multiple')) |
| 319 | { |
| 320 | $extra .= ' multiple="multiple"'; |
| 321 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 322 | |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 323 | return form_dropdown($name, $options, $selected, $extra); |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | // -------------------------------------------------------------------- |
| 328 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 329 | if ( ! function_exists('form_dropdown')) |
| 330 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 331 | /** |
| 332 | * Drop-down Menu |
| 333 | * |
Brennan Thompson | 40cd600 | 2014-02-14 12:06:38 -0700 | [diff] [blame] | 334 | * @param mixed $data |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 335 | * @param mixed $options |
| 336 | * @param mixed $selected |
| 337 | * @param mixed $extra |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 338 | * @return string |
| 339 | */ |
Brennan Thompson | 40cd600 | 2014-02-14 12:06:38 -0700 | [diff] [blame] | 340 | function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 341 | { |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 342 | $defaults = array(); |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 343 | |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 344 | if (is_array($data)) |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 345 | { |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 346 | if (isset($data['selected'])) |
| 347 | { |
| 348 | $selected = $data['selected']; |
| 349 | unset($data['selected']); // select tags don't have a selected attribute |
| 350 | } |
| 351 | |
| 352 | if (isset($data['options'])) |
| 353 | { |
| 354 | $options = $data['options']; |
| 355 | unset($data['options']); // select tags don't use an options attribute |
| 356 | } |
| 357 | } |
| 358 | else |
| 359 | { |
| 360 | $defaults = array('name' => $data); |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 361 | } |
| 362 | |
Andrey Andreev | 582ebcb | 2012-10-27 00:52:15 +0300 | [diff] [blame] | 363 | is_array($selected) OR $selected = array($selected); |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 364 | is_array($options) OR $options = array($options); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 365 | |
| 366 | // If no selected state was submitted we will attempt to set it automatically |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 367 | if (empty($selected)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 368 | { |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 369 | if (is_array($data)) |
| 370 | { |
| 371 | if (isset($data['name'], $_POST[$data['name']])) |
| 372 | { |
| 373 | $selected = array($_POST[$data['name']]); |
| 374 | } |
| 375 | } |
| 376 | elseif (isset($_POST[$data])) |
| 377 | { |
| 378 | $selected = array($_POST[$data]); |
| 379 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 380 | } |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 381 | |
Brennan Thompson | 1d03ef4 | 2014-02-17 12:08:22 -0700 | [diff] [blame] | 382 | $extra = _attributes_to_string($extra); |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 383 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 384 | $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 385 | |
Brennan Thompson | 1d03ef4 | 2014-02-17 12:08:22 -0700 | [diff] [blame] | 386 | $form = '<select '.rtrim(_parse_form_attributes($data, $defaults)).$extra.$multiple.">\n"; |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 387 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 388 | foreach ($options as $key => $val) |
| 389 | { |
| 390 | $key = (string) $key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 391 | |
Andrey Andreev | 6b114ae | 2012-07-13 12:05:52 +0300 | [diff] [blame] | 392 | if (is_array($val)) |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 393 | { |
Andrey Andreev | 6b114ae | 2012-07-13 12:05:52 +0300 | [diff] [blame] | 394 | if (empty($val)) |
| 395 | { |
| 396 | continue; |
| 397 | } |
| 398 | |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 399 | $form .= '<optgroup label="'.$key."\">\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 400 | |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 401 | foreach ($val as $optgroup_key => $optgroup_val) |
| 402 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 403 | $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : ''; |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 404 | $form .= '<option value="'.html_escape($optgroup_key).'"'.$sel.'>' |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 405 | .(string) $optgroup_val."</option>\n"; |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 406 | } |
| 407 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 408 | $form .= "</optgroup>\n"; |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 409 | } |
| 410 | else |
| 411 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 412 | $form .= '<option value="'.html_escape($key).'"' |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 413 | .(in_array($key, $selected) ? ' selected="selected"' : '').'>' |
| 414 | .(string) $val."</option>\n"; |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 415 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 416 | } |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 417 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 418 | return $form."</select>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | } |
| 420 | } |
| 421 | |
| 422 | // ------------------------------------------------------------------------ |
| 423 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 424 | if ( ! function_exists('form_checkbox')) |
| 425 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 426 | /** |
| 427 | * Checkbox Field |
| 428 | * |
| 429 | * @param mixed |
| 430 | * @param string |
| 431 | * @param bool |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 432 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 433 | * @return string |
| 434 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 435 | function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') |
| 436 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 437 | $defaults = array('type' => 'checkbox', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 438 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 439 | if (is_array($data) && array_key_exists('checked', $data)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 440 | { |
| 441 | $checked = $data['checked']; |
| 442 | |
Michiel Vugteveen | 910ff7a | 2012-06-06 20:03:14 +0200 | [diff] [blame] | 443 | if ($checked == FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 444 | { |
| 445 | unset($data['checked']); |
| 446 | } |
| 447 | else |
| 448 | { |
| 449 | $data['checked'] = 'checked'; |
| 450 | } |
| 451 | } |
| 452 | |
Michiel Vugteveen | 910ff7a | 2012-06-06 20:03:14 +0200 | [diff] [blame] | 453 | if ($checked == TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 454 | { |
| 455 | $defaults['checked'] = 'checked'; |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | unset($defaults['checked']); |
| 460 | } |
| 461 | |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 462 | $extra = _attributes_to_string($extra); |
| 463 | |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 464 | return '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | |
| 468 | // ------------------------------------------------------------------------ |
| 469 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 470 | if ( ! function_exists('form_radio')) |
| 471 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 472 | /** |
| 473 | * Radio Button |
| 474 | * |
| 475 | * @param mixed |
| 476 | * @param string |
| 477 | * @param bool |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 478 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 479 | * @return string |
| 480 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 481 | function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') |
| 482 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 483 | is_array($data) OR $data = array('name' => $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 484 | $data['type'] = 'radio'; |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 485 | |
| 486 | $extra = _attributes_to_string($extra); |
| 487 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 488 | return form_checkbox($data, $value, $checked, $extra); |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | // ------------------------------------------------------------------------ |
| 493 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 494 | if ( ! function_exists('form_submit')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 495 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 496 | /** |
| 497 | * Submit Button |
| 498 | * |
| 499 | * @param mixed |
| 500 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 501 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 502 | * @return string |
| 503 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 504 | function form_submit($data = '', $value = '', $extra = '') |
| 505 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 506 | $defaults = array( |
| 507 | 'type' => 'submit', |
| 508 | 'name' => is_array($data) ? '' : $data, |
| 509 | 'value' => $value |
| 510 | ); |
| 511 | |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 512 | $extra = _attributes_to_string($extra); |
| 513 | |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 514 | return '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 515 | } |
| 516 | } |
| 517 | |
| 518 | // ------------------------------------------------------------------------ |
| 519 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 520 | if ( ! function_exists('form_reset')) |
| 521 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 522 | /** |
| 523 | * Reset Button |
| 524 | * |
| 525 | * @param mixed |
| 526 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 527 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 528 | * @return string |
| 529 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 530 | function form_reset($data = '', $value = '', $extra = '') |
| 531 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 532 | $defaults = array( |
| 533 | 'type' => 'reset', |
| 534 | 'name' => is_array($data) ? '' : $data, |
| 535 | 'value' => $value |
| 536 | ); |
| 537 | |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 538 | $extra = _attributes_to_string($extra); |
| 539 | |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 540 | return '<input '._parse_form_attributes($data, $defaults).$extra." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
| 544 | // ------------------------------------------------------------------------ |
| 545 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 546 | if ( ! function_exists('form_button')) |
| 547 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 548 | /** |
| 549 | * Form Button |
| 550 | * |
| 551 | * @param mixed |
| 552 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 553 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 554 | * @return string |
| 555 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 556 | function form_button($data = '', $content = '', $extra = '') |
| 557 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 558 | $defaults = array( |
| 559 | 'name' => is_array($data) ? '' : $data, |
| 560 | 'type' => 'button' |
| 561 | ); |
| 562 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 563 | if (is_array($data) && isset($data['content'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 564 | { |
| 565 | $content = $data['content']; |
| 566 | unset($data['content']); // content is not an attribute |
| 567 | } |
| 568 | |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame^] | 569 | $extra = _attributes_to_string($extra); |
| 570 | |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 571 | return '<button '._parse_form_attributes($data, $defaults).$extra.'>'.$content."</button>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 572 | } |
| 573 | } |
| 574 | |
| 575 | // ------------------------------------------------------------------------ |
| 576 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 577 | if ( ! function_exists('form_label')) |
| 578 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 579 | /** |
| 580 | * Form Label Tag |
| 581 | * |
| 582 | * @param string The text to appear onscreen |
| 583 | * @param string The id the label applies to |
| 584 | * @param string Additional attributes |
| 585 | * @return string |
| 586 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 587 | function form_label($label_text = '', $id = '', $attributes = array()) |
| 588 | { |
| 589 | |
| 590 | $label = '<label'; |
| 591 | |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 592 | if ($id !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 593 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 594 | $label .= ' for="'.$id.'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 597 | if (is_array($attributes) && count($attributes) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 598 | { |
| 599 | foreach ($attributes as $key => $val) |
| 600 | { |
| 601 | $label .= ' '.$key.'="'.$val.'"'; |
| 602 | } |
| 603 | } |
| 604 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 605 | return $label.'>'.$label_text.'</label>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
| 609 | // ------------------------------------------------------------------------ |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 610 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 611 | if ( ! function_exists('form_fieldset')) |
| 612 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 613 | /** |
| 614 | * Fieldset Tag |
| 615 | * |
| 616 | * Used to produce <fieldset><legend>text</legend>. To close fieldset |
| 617 | * use form_fieldset_close() |
| 618 | * |
| 619 | * @param string The legend text |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 620 | * @param array Additional attributes |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 621 | * @return string |
| 622 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 623 | function form_fieldset($legend_text = '', $attributes = array()) |
| 624 | { |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 625 | $fieldset = '<fieldset'._attributes_to_string($attributes).">\n"; |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 626 | if ($legend_text !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 627 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 628 | return $fieldset.'<legend>'.$legend_text."</legend>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | return $fieldset; |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | // ------------------------------------------------------------------------ |
| 636 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 637 | if ( ! function_exists('form_fieldset_close')) |
| 638 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 639 | /** |
| 640 | * Fieldset Close Tag |
| 641 | * |
| 642 | * @param string |
| 643 | * @return string |
| 644 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 645 | function form_fieldset_close($extra = '') |
| 646 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 647 | return '</fieldset>'.$extra; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
| 651 | // ------------------------------------------------------------------------ |
| 652 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 653 | if ( ! function_exists('form_close')) |
| 654 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 655 | /** |
| 656 | * Form Close Tag |
| 657 | * |
| 658 | * @param string |
| 659 | * @return string |
| 660 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 661 | function form_close($extra = '') |
| 662 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 663 | return '</form>'.$extra; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 664 | } |
| 665 | } |
| 666 | |
| 667 | // ------------------------------------------------------------------------ |
| 668 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 669 | if ( ! function_exists('form_prep')) |
| 670 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 671 | /** |
| 672 | * Form Prep |
| 673 | * |
| 674 | * Formats text so that it can be safely placed in a form field in the event it has HTML tags. |
| 675 | * |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 676 | * @deprecated 3.0.0 An alias for html_escape() |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 677 | * @param string|string[] $str Value to escape |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 678 | * @return string|string[] Escaped values |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 679 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 680 | function form_prep($str) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 681 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 682 | return html_escape($str, TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 683 | } |
| 684 | } |
| 685 | |
| 686 | // ------------------------------------------------------------------------ |
| 687 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 688 | if ( ! function_exists('set_value')) |
| 689 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 690 | /** |
| 691 | * Form Value |
| 692 | * |
| 693 | * Grabs a value from the POST array for the specified field so you can |
| 694 | * re-populate an input field or textarea. If Form Validation |
| 695 | * is active it retrieves the info from the validation class |
| 696 | * |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 697 | * @param string $field Field name |
| 698 | * @param string $default Default value |
Adrian Voicu | fa61fb2 | 2015-02-05 15:46:12 +0200 | [diff] [blame] | 699 | * @param bool $html_escape Whether to escape HTML special characters or not |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 700 | * @return string |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 701 | */ |
Adrian Voicu | 86e6a19 | 2015-02-05 13:51:26 +0200 | [diff] [blame] | 702 | function set_value($field, $default = '', $html_escape = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 703 | { |
nisheeth-barthwal | 77236e0 | 2013-03-25 23:42:36 +0530 | [diff] [blame] | 704 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 705 | |
nisheeth-barthwal | 47ea5a8 | 2013-03-26 18:57:28 +0530 | [diff] [blame] | 706 | $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) |
| 707 | ? $CI->form_validation->set_value($field, $default) |
| 708 | : $CI->input->post($field, FALSE); |
Andrey Andreev | 7df6634 | 2015-02-05 15:58:09 +0200 | [diff] [blame] | 709 | |
Adrian Voicu | 86e6a19 | 2015-02-05 13:51:26 +0200 | [diff] [blame] | 710 | isset($value) OR $value = $default; |
| 711 | return ($html_escape) ? html_escape($value) : $value; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
| 715 | // ------------------------------------------------------------------------ |
| 716 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 717 | if ( ! function_exists('set_select')) |
| 718 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 719 | /** |
| 720 | * Set Select |
| 721 | * |
| 722 | * Let's you set the selected value of a <select> menu via data in the POST array. |
| 723 | * If Form Validation is active it retrieves the info from the validation class |
| 724 | * |
| 725 | * @param string |
| 726 | * @param string |
| 727 | * @param bool |
| 728 | * @return string |
| 729 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 730 | function set_select($field, $value = '', $default = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 731 | { |
Andrey Andreev | 67f6a5e | 2013-09-13 16:21:31 +0300 | [diff] [blame] | 732 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 733 | |
Andrey Andreev | 67f6a5e | 2013-09-13 16:21:31 +0300 | [diff] [blame] | 734 | if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 735 | { |
Andrey Andreev | 67f6a5e | 2013-09-13 16:21:31 +0300 | [diff] [blame] | 736 | return $CI->form_validation->set_select($field, $value, $default); |
| 737 | } |
| 738 | elseif (($input = $CI->input->post($field, FALSE)) === NULL) |
| 739 | { |
| 740 | return ($default === TRUE) ? ' selected="selected"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 741 | } |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 742 | |
| 743 | $value = (string) $value; |
| 744 | if (is_array($input)) |
Andrey Andreev | d3b7e24 | 2013-09-13 18:36:29 +0300 | [diff] [blame] | 745 | { |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 746 | // Note: in_array('', array(0)) returns TRUE, do not use it |
| 747 | foreach ($input as &$v) |
| 748 | { |
| 749 | if ($value === $v) |
| 750 | { |
| 751 | return ' selected="selected"'; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | return ''; |
Andrey Andreev | d3b7e24 | 2013-09-13 18:36:29 +0300 | [diff] [blame] | 756 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 757 | |
Andrey Andreev | d3b7e24 | 2013-09-13 18:36:29 +0300 | [diff] [blame] | 758 | return ($input === $value) ? ' selected="selected"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 759 | } |
| 760 | } |
| 761 | |
| 762 | // ------------------------------------------------------------------------ |
| 763 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 764 | if ( ! function_exists('set_checkbox')) |
| 765 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 766 | /** |
| 767 | * Set Checkbox |
| 768 | * |
| 769 | * Let's you set the selected value of a checkbox via the value in the POST array. |
| 770 | * If Form Validation is active it retrieves the info from the validation class |
| 771 | * |
| 772 | * @param string |
| 773 | * @param string |
| 774 | * @param bool |
| 775 | * @return string |
| 776 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 777 | function set_checkbox($field, $value = '', $default = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 778 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 779 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 780 | |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 781 | if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 782 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 783 | return $CI->form_validation->set_checkbox($field, $value, $default); |
| 784 | } |
| 785 | elseif (($input = $CI->input->post($field, FALSE)) === NULL) |
| 786 | { |
| 787 | return ($default === TRUE) ? ' checked="checked"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 788 | } |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 789 | |
| 790 | $value = (string) $value; |
| 791 | if (is_array($input)) |
Andrey Andreev | e8a23a5 | 2013-09-13 18:29:29 +0300 | [diff] [blame] | 792 | { |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 793 | // Note: in_array('', array(0)) returns TRUE, do not use it |
| 794 | foreach ($input as &$v) |
| 795 | { |
| 796 | if ($value === $v) |
| 797 | { |
| 798 | return ' checked="checked"'; |
| 799 | } |
| 800 | } |
| 801 | |
| 802 | return ''; |
Andrey Andreev | e8a23a5 | 2013-09-13 18:29:29 +0300 | [diff] [blame] | 803 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 804 | |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 805 | return ($input === $value) ? ' checked="checked"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | |
| 809 | // ------------------------------------------------------------------------ |
| 810 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 811 | if ( ! function_exists('set_radio')) |
| 812 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 813 | /** |
| 814 | * Set Radio |
| 815 | * |
| 816 | * Let's you set the selected value of a radio field via info in the POST array. |
| 817 | * If Form Validation is active it retrieves the info from the validation class |
| 818 | * |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 819 | * @param string $field |
| 820 | * @param string $value |
| 821 | * @param bool $default |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 822 | * @return string |
| 823 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 824 | function set_radio($field, $value = '', $default = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 825 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 826 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 827 | |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 828 | if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 829 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 830 | return $CI->form_validation->set_radio($field, $value, $default); |
| 831 | } |
| 832 | elseif (($input = $CI->input->post($field, FALSE)) === NULL) |
| 833 | { |
| 834 | return ($default === TRUE) ? ' checked="checked"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 835 | } |
| 836 | |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 837 | return ($input === (string) $value) ? ' checked="checked"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
| 841 | // ------------------------------------------------------------------------ |
| 842 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 843 | if ( ! function_exists('form_error')) |
| 844 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 845 | /** |
| 846 | * Form Error |
| 847 | * |
| 848 | * Returns the error for a specific form field. This is a helper for the |
| 849 | * form validation class. |
| 850 | * |
| 851 | * @param string |
| 852 | * @param string |
| 853 | * @param string |
| 854 | * @return string |
| 855 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 856 | function form_error($field = '', $prefix = '', $suffix = '') |
| 857 | { |
| 858 | if (FALSE === ($OBJ =& _get_validation_object())) |
| 859 | { |
| 860 | return ''; |
| 861 | } |
| 862 | |
| 863 | return $OBJ->error($field, $prefix, $suffix); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | // ------------------------------------------------------------------------ |
| 868 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 869 | if ( ! function_exists('validation_errors')) |
| 870 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 871 | /** |
| 872 | * Validation Error String |
| 873 | * |
| 874 | * Returns all the errors associated with a form submission. This is a helper |
| 875 | * function for the form validation class. |
| 876 | * |
| 877 | * @param string |
| 878 | * @param string |
| 879 | * @return string |
| 880 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 881 | function validation_errors($prefix = '', $suffix = '') |
| 882 | { |
| 883 | if (FALSE === ($OBJ =& _get_validation_object())) |
Greg Aker | c83bea6 | 2011-04-23 12:12:57 -0500 | [diff] [blame] | 884 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 885 | return ''; |
| 886 | } |
| 887 | |
| 888 | return $OBJ->error_string($prefix, $suffix); |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | // ------------------------------------------------------------------------ |
| 893 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 894 | if ( ! function_exists('_parse_form_attributes')) |
| 895 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 896 | /** |
| 897 | * Parse the form attributes |
| 898 | * |
| 899 | * Helper function used by some of the form helpers |
| 900 | * |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 901 | * @param array $attributes List of attributes |
| 902 | * @param array $default Default values |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 903 | * @return string |
| 904 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 905 | function _parse_form_attributes($attributes, $default) |
| 906 | { |
| 907 | if (is_array($attributes)) |
| 908 | { |
| 909 | foreach ($default as $key => $val) |
| 910 | { |
| 911 | if (isset($attributes[$key])) |
| 912 | { |
| 913 | $default[$key] = $attributes[$key]; |
| 914 | unset($attributes[$key]); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | if (count($attributes) > 0) |
| 919 | { |
| 920 | $default = array_merge($default, $attributes); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | $att = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 925 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 926 | foreach ($default as $key => $val) |
| 927 | { |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 928 | if ($key === 'value') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 929 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 930 | $val = html_escape($val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 931 | } |
Andrey Andreev | 60b9714 | 2012-10-25 16:59:17 +0300 | [diff] [blame] | 932 | elseif ($key === 'name' && ! strlen($default['name'])) |
| 933 | { |
| 934 | continue; |
| 935 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 936 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 937 | $att .= $key.'="'.$val.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | return $att; |
| 941 | } |
| 942 | } |
| 943 | |
| 944 | // ------------------------------------------------------------------------ |
| 945 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 946 | if ( ! function_exists('_attributes_to_string')) |
| 947 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 948 | /** |
| 949 | * Attributes To String |
| 950 | * |
| 951 | * Helper function used by some of the form helpers |
| 952 | * |
| 953 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 954 | * @return string |
| 955 | */ |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 956 | function _attributes_to_string($attributes) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 957 | { |
vlakoff | bb8b089 | 2013-07-28 22:35:04 +0200 | [diff] [blame] | 958 | if (empty($attributes)) |
| 959 | { |
| 960 | return ''; |
| 961 | } |
| 962 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 963 | if (is_object($attributes)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 964 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 965 | $attributes = (array) $attributes; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 966 | } |
| 967 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 968 | if (is_array($attributes)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 969 | { |
Derek Allard | 3241d73 | 2009-09-17 12:17:45 +0000 | [diff] [blame] | 970 | $atts = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 971 | |
Derek Allard | 3241d73 | 2009-09-17 12:17:45 +0000 | [diff] [blame] | 972 | foreach ($attributes as $key => $val) |
| 973 | { |
| 974 | $atts .= ' '.$key.'="'.$val.'"'; |
| 975 | } |
| 976 | |
| 977 | return $atts; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 978 | } |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 979 | |
vlakoff | f746475 | 2013-07-28 22:23:21 +0200 | [diff] [blame] | 980 | if (is_string($attributes)) |
| 981 | { |
Brennan Thompson | 7a772e5 | 2014-02-16 19:22:54 -0700 | [diff] [blame] | 982 | return ' '.$attributes; |
vlakoff | f746475 | 2013-07-28 22:23:21 +0200 | [diff] [blame] | 983 | } |
| 984 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 985 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | |
| 989 | // ------------------------------------------------------------------------ |
| 990 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 991 | if ( ! function_exists('_get_validation_object')) |
| 992 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 993 | /** |
| 994 | * Validation Object |
| 995 | * |
| 996 | * Determines what the form validation class was instantiated as, fetches |
| 997 | * the object and returns it. |
| 998 | * |
| 999 | * @return mixed |
| 1000 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1001 | function &_get_validation_object() |
| 1002 | { |
| 1003 | $CI =& get_instance(); |
| 1004 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1005 | // We set this as a variable since we're returning by reference. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1006 | $return = FALSE; |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 1007 | |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1008 | if (FALSE !== ($object = $CI->load->is_loaded('Form_validation'))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1009 | { |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1010 | if ( ! isset($CI->$object) OR ! is_object($CI->$object)) |
| 1011 | { |
| 1012 | return $return; |
| 1013 | } |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 1014 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1015 | return $CI->$object; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1016 | } |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 1017 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1018 | return $return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1019 | } |
| 1020 | } |