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 | 125ef47 | 2016-01-11 12:33:00 +0200 | [diff] [blame] | 9 | * Copyright (c) 2014 - 2016, 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 |
Andrey Andreev | 1924e87 | 2016-01-11 12:55:34 +0200 | [diff] [blame] | 31 | * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/) |
Andrey Andreev | 125ef47 | 2016-01-11 12:33:00 +0200 | [diff] [blame] | 32 | * @copyright Copyright (c) 2014 - 2016, 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 |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 34 | * @link https://codeigniter.com |
Andrey Andreev | bdb96ca | 2014-10-28 00:13:31 +0200 | [diff] [blame] | 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 |
Andrey Andreev | bd202c9 | 2016-01-11 12:50:18 +0200 | [diff] [blame] | 47 | * @link https://codeigniter.com/user_guide/helpers/form_helper.html |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 211 | return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | // ------------------------------------------------------------------------ |
| 216 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 217 | if ( ! function_exists('form_password')) |
| 218 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 219 | /** |
| 220 | * Password Field |
| 221 | * |
| 222 | * Identical to the input function but adds the "password" type |
| 223 | * |
| 224 | * @param mixed |
| 225 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 226 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 227 | * @return string |
| 228 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 229 | function form_password($data = '', $value = '', $extra = '') |
| 230 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 231 | is_array($data) OR $data = array('name' => $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 232 | $data['type'] = 'password'; |
| 233 | return form_input($data, $value, $extra); |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | // ------------------------------------------------------------------------ |
| 238 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 239 | if ( ! function_exists('form_upload')) |
| 240 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 241 | /** |
| 242 | * Upload Field |
| 243 | * |
| 244 | * Identical to the input function but adds the "file" type |
| 245 | * |
| 246 | * @param mixed |
| 247 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 248 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 249 | * @return string |
| 250 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 251 | function form_upload($data = '', $value = '', $extra = '') |
| 252 | { |
Bo-Yi Wu | 06ddcf0 | 2013-02-18 08:52:05 +0800 | [diff] [blame] | 253 | $defaults = array('type' => 'file', 'name' => ''); |
Andrey Andreev | 99ba3a2 | 2013-02-15 22:42:22 +0200 | [diff] [blame] | 254 | is_array($data) OR $data = array('name' => $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 255 | $data['type'] = 'file'; |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 256 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 257 | return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | // ------------------------------------------------------------------------ |
| 262 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 263 | if ( ! function_exists('form_textarea')) |
| 264 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 265 | /** |
| 266 | * Textarea field |
| 267 | * |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 268 | * @param mixed $data |
| 269 | * @param string $value |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 270 | * @param mixed $extra |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 271 | * @return string |
| 272 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 273 | function form_textarea($data = '', $value = '', $extra = '') |
| 274 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 275 | $defaults = array( |
| 276 | 'name' => is_array($data) ? '' : $data, |
| 277 | 'cols' => '40', |
| 278 | 'rows' => '10' |
| 279 | ); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 280 | |
| 281 | if ( ! is_array($data) OR ! isset($data['value'])) |
| 282 | { |
| 283 | $val = $value; |
| 284 | } |
| 285 | else |
| 286 | { |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 287 | $val = $data['value']; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 288 | unset($data['value']); // textareas don't use the value attribute |
| 289 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 290 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 291 | return '<textarea '._parse_form_attributes($data, $defaults)._attributes_to_string($extra).'>' |
| 292 | .html_escape($val) |
| 293 | ."</textarea>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | // ------------------------------------------------------------------------ |
| 298 | |
Derek Jones | 68788d5 | 2010-03-05 10:11:31 -0600 | [diff] [blame] | 299 | if ( ! function_exists('form_multiselect')) |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 300 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 301 | /** |
| 302 | * Multi-select menu |
| 303 | * |
| 304 | * @param string |
| 305 | * @param array |
| 306 | * @param mixed |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 307 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 308 | * @return string |
| 309 | */ |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 310 | function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '') |
| 311 | { |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 312 | $extra = _attributes_to_string($extra); |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 313 | if (stripos($extra, 'multiple') === FALSE) |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 314 | { |
| 315 | $extra .= ' multiple="multiple"'; |
| 316 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 317 | |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 318 | return form_dropdown($name, $options, $selected, $extra); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // -------------------------------------------------------------------- |
| 323 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 324 | if ( ! function_exists('form_dropdown')) |
| 325 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 326 | /** |
| 327 | * Drop-down Menu |
| 328 | * |
Brennan Thompson | 40cd600 | 2014-02-14 12:06:38 -0700 | [diff] [blame] | 329 | * @param mixed $data |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 330 | * @param mixed $options |
| 331 | * @param mixed $selected |
| 332 | * @param mixed $extra |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 333 | * @return string |
| 334 | */ |
Brennan Thompson | 40cd600 | 2014-02-14 12:06:38 -0700 | [diff] [blame] | 335 | function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 336 | { |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 337 | $defaults = array(); |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 338 | |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 339 | if (is_array($data)) |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 340 | { |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 341 | if (isset($data['selected'])) |
| 342 | { |
| 343 | $selected = $data['selected']; |
| 344 | unset($data['selected']); // select tags don't have a selected attribute |
| 345 | } |
| 346 | |
| 347 | if (isset($data['options'])) |
| 348 | { |
| 349 | $options = $data['options']; |
| 350 | unset($data['options']); // select tags don't use an options attribute |
| 351 | } |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | $defaults = array('name' => $data); |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 356 | } |
| 357 | |
Andrey Andreev | 582ebcb | 2012-10-27 00:52:15 +0300 | [diff] [blame] | 358 | is_array($selected) OR $selected = array($selected); |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 359 | is_array($options) OR $options = array($options); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 360 | |
| 361 | // 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] | 362 | if (empty($selected)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 363 | { |
Andrey Andreev | 15662dd | 2014-03-06 13:45:33 +0200 | [diff] [blame] | 364 | if (is_array($data)) |
| 365 | { |
| 366 | if (isset($data['name'], $_POST[$data['name']])) |
| 367 | { |
| 368 | $selected = array($_POST[$data['name']]); |
| 369 | } |
| 370 | } |
| 371 | elseif (isset($_POST[$data])) |
| 372 | { |
| 373 | $selected = array($_POST[$data]); |
| 374 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 375 | } |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 376 | |
Brennan Thompson | 1d03ef4 | 2014-02-17 12:08:22 -0700 | [diff] [blame] | 377 | $extra = _attributes_to_string($extra); |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 378 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 379 | $multiple = (count($selected) > 1 && stripos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : ''; |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 380 | |
Brennan Thompson | 1d03ef4 | 2014-02-17 12:08:22 -0700 | [diff] [blame] | 381 | $form = '<select '.rtrim(_parse_form_attributes($data, $defaults)).$extra.$multiple.">\n"; |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 382 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 383 | foreach ($options as $key => $val) |
| 384 | { |
| 385 | $key = (string) $key; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 386 | |
Andrey Andreev | 6b114ae | 2012-07-13 12:05:52 +0300 | [diff] [blame] | 387 | if (is_array($val)) |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 388 | { |
Andrey Andreev | 6b114ae | 2012-07-13 12:05:52 +0300 | [diff] [blame] | 389 | if (empty($val)) |
| 390 | { |
| 391 | continue; |
| 392 | } |
| 393 | |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 394 | $form .= '<optgroup label="'.$key."\">\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 395 | |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 396 | foreach ($val as $optgroup_key => $optgroup_val) |
| 397 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 398 | $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : ''; |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 399 | $form .= '<option value="'.html_escape($optgroup_key).'"'.$sel.'>' |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 400 | .(string) $optgroup_val."</option>\n"; |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 403 | $form .= "</optgroup>\n"; |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 404 | } |
| 405 | else |
| 406 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 407 | $form .= '<option value="'.html_escape($key).'"' |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 408 | .(in_array($key, $selected) ? ' selected="selected"' : '').'>' |
| 409 | .(string) $val."</option>\n"; |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 410 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 411 | } |
Brennan Thompson | 82c78a9 | 2014-02-17 10:02:19 -0700 | [diff] [blame] | 412 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 413 | return $form."</select>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | |
| 417 | // ------------------------------------------------------------------------ |
| 418 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 419 | if ( ! function_exists('form_checkbox')) |
| 420 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 421 | /** |
| 422 | * Checkbox Field |
| 423 | * |
| 424 | * @param mixed |
| 425 | * @param string |
| 426 | * @param bool |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 427 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 428 | * @return string |
| 429 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 430 | function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '') |
| 431 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 432 | $defaults = array('type' => 'checkbox', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 433 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 434 | if (is_array($data) && array_key_exists('checked', $data)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 435 | { |
| 436 | $checked = $data['checked']; |
| 437 | |
Michiel Vugteveen | 910ff7a | 2012-06-06 20:03:14 +0200 | [diff] [blame] | 438 | if ($checked == FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 439 | { |
| 440 | unset($data['checked']); |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | $data['checked'] = 'checked'; |
| 445 | } |
| 446 | } |
| 447 | |
Michiel Vugteveen | 910ff7a | 2012-06-06 20:03:14 +0200 | [diff] [blame] | 448 | if ($checked == TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 449 | { |
| 450 | $defaults['checked'] = 'checked'; |
| 451 | } |
| 452 | else |
| 453 | { |
| 454 | unset($defaults['checked']); |
| 455 | } |
| 456 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 457 | return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | |
| 461 | // ------------------------------------------------------------------------ |
| 462 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 463 | if ( ! function_exists('form_radio')) |
| 464 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 465 | /** |
| 466 | * Radio Button |
| 467 | * |
| 468 | * @param mixed |
| 469 | * @param string |
| 470 | * @param bool |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 471 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 472 | * @return string |
| 473 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 474 | function form_radio($data = '', $value = '', $checked = FALSE, $extra = '') |
| 475 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 476 | is_array($data) OR $data = array('name' => $data); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 477 | $data['type'] = 'radio'; |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 478 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 479 | return form_checkbox($data, $value, $checked, $extra); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | // ------------------------------------------------------------------------ |
| 484 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 485 | if ( ! function_exists('form_submit')) |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 486 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 487 | /** |
| 488 | * Submit Button |
| 489 | * |
| 490 | * @param mixed |
| 491 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 492 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 493 | * @return string |
| 494 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 495 | function form_submit($data = '', $value = '', $extra = '') |
| 496 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 497 | $defaults = array( |
| 498 | 'type' => 'submit', |
| 499 | 'name' => is_array($data) ? '' : $data, |
| 500 | 'value' => $value |
| 501 | ); |
| 502 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 503 | return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
| 507 | // ------------------------------------------------------------------------ |
| 508 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 509 | if ( ! function_exists('form_reset')) |
| 510 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 511 | /** |
| 512 | * Reset Button |
| 513 | * |
| 514 | * @param mixed |
| 515 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 516 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 517 | * @return string |
| 518 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 519 | function form_reset($data = '', $value = '', $extra = '') |
| 520 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 521 | $defaults = array( |
| 522 | 'type' => 'reset', |
| 523 | 'name' => is_array($data) ? '' : $data, |
| 524 | 'value' => $value |
| 525 | ); |
| 526 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 527 | return '<input '._parse_form_attributes($data, $defaults)._attributes_to_string($extra)." />\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
| 531 | // ------------------------------------------------------------------------ |
| 532 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 533 | if ( ! function_exists('form_button')) |
| 534 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 535 | /** |
| 536 | * Form Button |
| 537 | * |
| 538 | * @param mixed |
| 539 | * @param string |
Adam Jackett | 664d25a | 2015-06-03 15:54:54 -0400 | [diff] [blame] | 540 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 541 | * @return string |
| 542 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 543 | function form_button($data = '', $content = '', $extra = '') |
| 544 | { |
Andrey Andreev | ea41c8a | 2014-02-26 18:31:02 +0200 | [diff] [blame] | 545 | $defaults = array( |
| 546 | 'name' => is_array($data) ? '' : $data, |
| 547 | 'type' => 'button' |
| 548 | ); |
| 549 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 550 | if (is_array($data) && isset($data['content'])) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 551 | { |
| 552 | $content = $data['content']; |
| 553 | unset($data['content']); // content is not an attribute |
| 554 | } |
| 555 | |
Andrey Andreev | c19f3b2 | 2015-07-15 16:41:06 +0300 | [diff] [blame] | 556 | return '<button '._parse_form_attributes($data, $defaults)._attributes_to_string($extra).'>' |
| 557 | .$content |
| 558 | ."</button>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | |
| 562 | // ------------------------------------------------------------------------ |
| 563 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 564 | if ( ! function_exists('form_label')) |
| 565 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 566 | /** |
| 567 | * Form Label Tag |
| 568 | * |
| 569 | * @param string The text to appear onscreen |
| 570 | * @param string The id the label applies to |
| 571 | * @param string Additional attributes |
| 572 | * @return string |
| 573 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 574 | function form_label($label_text = '', $id = '', $attributes = array()) |
| 575 | { |
| 576 | |
| 577 | $label = '<label'; |
| 578 | |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 579 | if ($id !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 580 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 581 | $label .= ' for="'.$id.'"'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 584 | if (is_array($attributes) && count($attributes) > 0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 585 | { |
| 586 | foreach ($attributes as $key => $val) |
| 587 | { |
| 588 | $label .= ' '.$key.'="'.$val.'"'; |
| 589 | } |
| 590 | } |
| 591 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 592 | return $label.'>'.$label_text.'</label>'; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | |
| 596 | // ------------------------------------------------------------------------ |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 597 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 598 | if ( ! function_exists('form_fieldset')) |
| 599 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 600 | /** |
| 601 | * Fieldset Tag |
| 602 | * |
| 603 | * Used to produce <fieldset><legend>text</legend>. To close fieldset |
| 604 | * use form_fieldset_close() |
| 605 | * |
| 606 | * @param string The legend text |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 607 | * @param array Additional attributes |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 608 | * @return string |
| 609 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 610 | function form_fieldset($legend_text = '', $attributes = array()) |
| 611 | { |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 612 | $fieldset = '<fieldset'._attributes_to_string($attributes).">\n"; |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 613 | if ($legend_text !== '') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 614 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 615 | return $fieldset.'<legend>'.$legend_text."</legend>\n"; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | return $fieldset; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | // ------------------------------------------------------------------------ |
| 623 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 624 | if ( ! function_exists('form_fieldset_close')) |
| 625 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 626 | /** |
| 627 | * Fieldset Close Tag |
| 628 | * |
| 629 | * @param string |
| 630 | * @return string |
| 631 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 632 | function form_fieldset_close($extra = '') |
| 633 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 634 | return '</fieldset>'.$extra; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
| 638 | // ------------------------------------------------------------------------ |
| 639 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 640 | if ( ! function_exists('form_close')) |
| 641 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 642 | /** |
| 643 | * Form Close Tag |
| 644 | * |
| 645 | * @param string |
| 646 | * @return string |
| 647 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 648 | function form_close($extra = '') |
| 649 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 650 | return '</form>'.$extra; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
| 654 | // ------------------------------------------------------------------------ |
| 655 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 656 | if ( ! function_exists('form_prep')) |
| 657 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 658 | /** |
| 659 | * Form Prep |
| 660 | * |
| 661 | * Formats text so that it can be safely placed in a form field in the event it has HTML tags. |
| 662 | * |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 663 | * @deprecated 3.0.0 An alias for html_escape() |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 664 | * @param string|string[] $str Value to escape |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 665 | * @return string|string[] Escaped values |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 666 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 667 | function form_prep($str) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 668 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 669 | return html_escape($str, TRUE); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
| 673 | // ------------------------------------------------------------------------ |
| 674 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 675 | if ( ! function_exists('set_value')) |
| 676 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 677 | /** |
| 678 | * Form Value |
| 679 | * |
| 680 | * Grabs a value from the POST array for the specified field so you can |
| 681 | * re-populate an input field or textarea. If Form Validation |
| 682 | * is active it retrieves the info from the validation class |
| 683 | * |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 684 | * @param string $field Field name |
| 685 | * @param string $default Default value |
Adrian Voicu | fa61fb2 | 2015-02-05 15:46:12 +0200 | [diff] [blame] | 686 | * @param bool $html_escape Whether to escape HTML special characters or not |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 687 | * @return string |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 688 | */ |
Adrian Voicu | 86e6a19 | 2015-02-05 13:51:26 +0200 | [diff] [blame] | 689 | function set_value($field, $default = '', $html_escape = TRUE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 690 | { |
nisheeth-barthwal | 77236e0 | 2013-03-25 23:42:36 +0530 | [diff] [blame] | 691 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 692 | |
nisheeth-barthwal | 47ea5a8 | 2013-03-26 18:57:28 +0530 | [diff] [blame] | 693 | $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field)) |
| 694 | ? $CI->form_validation->set_value($field, $default) |
| 695 | : $CI->input->post($field, FALSE); |
Andrey Andreev | 7df6634 | 2015-02-05 15:58:09 +0200 | [diff] [blame] | 696 | |
Adrian Voicu | 86e6a19 | 2015-02-05 13:51:26 +0200 | [diff] [blame] | 697 | isset($value) OR $value = $default; |
| 698 | return ($html_escape) ? html_escape($value) : $value; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 699 | } |
| 700 | } |
| 701 | |
| 702 | // ------------------------------------------------------------------------ |
| 703 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 704 | if ( ! function_exists('set_select')) |
| 705 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 706 | /** |
| 707 | * Set Select |
| 708 | * |
| 709 | * Let's you set the selected value of a <select> menu via data in the POST array. |
| 710 | * If Form Validation is active it retrieves the info from the validation class |
| 711 | * |
| 712 | * @param string |
| 713 | * @param string |
| 714 | * @param bool |
| 715 | * @return string |
| 716 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 717 | function set_select($field, $value = '', $default = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 718 | { |
Andrey Andreev | 67f6a5e | 2013-09-13 16:21:31 +0300 | [diff] [blame] | 719 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 720 | |
Andrey Andreev | 67f6a5e | 2013-09-13 16:21:31 +0300 | [diff] [blame] | 721 | 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] | 722 | { |
Andrey Andreev | 67f6a5e | 2013-09-13 16:21:31 +0300 | [diff] [blame] | 723 | return $CI->form_validation->set_select($field, $value, $default); |
| 724 | } |
| 725 | elseif (($input = $CI->input->post($field, FALSE)) === NULL) |
| 726 | { |
| 727 | return ($default === TRUE) ? ' selected="selected"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 728 | } |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 729 | |
| 730 | $value = (string) $value; |
| 731 | if (is_array($input)) |
Andrey Andreev | d3b7e24 | 2013-09-13 18:36:29 +0300 | [diff] [blame] | 732 | { |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 733 | // Note: in_array('', array(0)) returns TRUE, do not use it |
| 734 | foreach ($input as &$v) |
| 735 | { |
| 736 | if ($value === $v) |
| 737 | { |
| 738 | return ' selected="selected"'; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return ''; |
Andrey Andreev | d3b7e24 | 2013-09-13 18:36:29 +0300 | [diff] [blame] | 743 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 744 | |
Andrey Andreev | d3b7e24 | 2013-09-13 18:36:29 +0300 | [diff] [blame] | 745 | return ($input === $value) ? ' selected="selected"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
| 749 | // ------------------------------------------------------------------------ |
| 750 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 751 | if ( ! function_exists('set_checkbox')) |
| 752 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 753 | /** |
| 754 | * Set Checkbox |
| 755 | * |
| 756 | * Let's you set the selected value of a checkbox via the value in the POST array. |
| 757 | * If Form Validation is active it retrieves the info from the validation class |
| 758 | * |
| 759 | * @param string |
| 760 | * @param string |
| 761 | * @param bool |
| 762 | * @return string |
| 763 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 764 | function set_checkbox($field, $value = '', $default = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 765 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 766 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 767 | |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 768 | 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] | 769 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 770 | return $CI->form_validation->set_checkbox($field, $value, $default); |
| 771 | } |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 772 | |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 773 | // Form inputs are always strings ... |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 774 | $value = (string) $value; |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 775 | $input = $CI->input->post($field, FALSE); |
| 776 | |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 777 | if (is_array($input)) |
Andrey Andreev | e8a23a5 | 2013-09-13 18:29:29 +0300 | [diff] [blame] | 778 | { |
Andrey Andreev | a587a93 | 2013-10-23 19:57:46 +0300 | [diff] [blame] | 779 | // Note: in_array('', array(0)) returns TRUE, do not use it |
| 780 | foreach ($input as &$v) |
| 781 | { |
| 782 | if ($value === $v) |
| 783 | { |
| 784 | return ' checked="checked"'; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | return ''; |
Andrey Andreev | e8a23a5 | 2013-09-13 18:29:29 +0300 | [diff] [blame] | 789 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 790 | |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 791 | // Unchecked checkbox and radio inputs are not even submitted by browsers ... |
| 792 | if ($CI->input->method() === 'post') |
| 793 | { |
Andrey Andreev | 0b59bdd | 2016-01-29 01:18:08 +0200 | [diff] [blame^] | 794 | return ($input === $value) ? ' checked="checked"' : ''; |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | return ($default === TRUE) ? ' checked="checked"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | |
| 801 | // ------------------------------------------------------------------------ |
| 802 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 803 | if ( ! function_exists('set_radio')) |
| 804 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 805 | /** |
| 806 | * Set Radio |
| 807 | * |
| 808 | * Let's you set the selected value of a radio field via info in the POST array. |
| 809 | * If Form Validation is active it retrieves the info from the validation class |
| 810 | * |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 811 | * @param string $field |
| 812 | * @param string $value |
| 813 | * @param bool $default |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 814 | * @return string |
| 815 | */ |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 816 | function set_radio($field, $value = '', $default = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 817 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 818 | $CI =& get_instance(); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 819 | |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 820 | 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] | 821 | { |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 822 | return $CI->form_validation->set_radio($field, $value, $default); |
| 823 | } |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 824 | |
| 825 | // Form inputs are always strings ... |
| 826 | $value = (string) $value; |
| 827 | $input = $CI->input->post($field, FALSE); |
| 828 | |
| 829 | if (is_array($input)) |
Andrey Andreev | ae50f55 | 2013-09-13 16:17:41 +0300 | [diff] [blame] | 830 | { |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 831 | // Note: in_array('', array(0)) returns TRUE, do not use it |
| 832 | foreach ($input as &$v) |
| 833 | { |
| 834 | if ($value === $v) |
| 835 | { |
| 836 | return ' checked="checked"'; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | return ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 841 | } |
| 842 | |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 843 | // Unchecked checkbox and radio inputs are not even submitted by browsers ... |
| 844 | if ($CI->input->method() === 'post') |
| 845 | { |
Andrey Andreev | 0b59bdd | 2016-01-29 01:18:08 +0200 | [diff] [blame^] | 846 | return ($input === $value) ? ' checked="checked"' : ''; |
Andrey Andreev | 0139e6a | 2015-11-04 22:42:17 +0200 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | return ($default === TRUE) ? ' checked="checked"' : ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | |
| 853 | // ------------------------------------------------------------------------ |
| 854 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 855 | if ( ! function_exists('form_error')) |
| 856 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 857 | /** |
| 858 | * Form Error |
| 859 | * |
| 860 | * Returns the error for a specific form field. This is a helper for the |
| 861 | * form validation class. |
| 862 | * |
| 863 | * @param string |
| 864 | * @param string |
| 865 | * @param string |
| 866 | * @return string |
| 867 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 868 | function form_error($field = '', $prefix = '', $suffix = '') |
| 869 | { |
| 870 | if (FALSE === ($OBJ =& _get_validation_object())) |
| 871 | { |
| 872 | return ''; |
| 873 | } |
| 874 | |
| 875 | return $OBJ->error($field, $prefix, $suffix); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | // ------------------------------------------------------------------------ |
| 880 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 881 | if ( ! function_exists('validation_errors')) |
| 882 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 883 | /** |
| 884 | * Validation Error String |
| 885 | * |
| 886 | * Returns all the errors associated with a form submission. This is a helper |
| 887 | * function for the form validation class. |
| 888 | * |
| 889 | * @param string |
| 890 | * @param string |
| 891 | * @return string |
| 892 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 893 | function validation_errors($prefix = '', $suffix = '') |
| 894 | { |
| 895 | if (FALSE === ($OBJ =& _get_validation_object())) |
Greg Aker | c83bea6 | 2011-04-23 12:12:57 -0500 | [diff] [blame] | 896 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 897 | return ''; |
| 898 | } |
| 899 | |
| 900 | return $OBJ->error_string($prefix, $suffix); |
| 901 | } |
| 902 | } |
| 903 | |
| 904 | // ------------------------------------------------------------------------ |
| 905 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 906 | if ( ! function_exists('_parse_form_attributes')) |
| 907 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 908 | /** |
| 909 | * Parse the form attributes |
| 910 | * |
| 911 | * Helper function used by some of the form helpers |
| 912 | * |
Andrey Andreev | 7c4d106 | 2012-11-01 15:14:34 +0200 | [diff] [blame] | 913 | * @param array $attributes List of attributes |
| 914 | * @param array $default Default values |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 915 | * @return string |
| 916 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 917 | function _parse_form_attributes($attributes, $default) |
| 918 | { |
| 919 | if (is_array($attributes)) |
| 920 | { |
| 921 | foreach ($default as $key => $val) |
| 922 | { |
| 923 | if (isset($attributes[$key])) |
| 924 | { |
| 925 | $default[$key] = $attributes[$key]; |
| 926 | unset($attributes[$key]); |
| 927 | } |
| 928 | } |
| 929 | |
| 930 | if (count($attributes) > 0) |
| 931 | { |
| 932 | $default = array_merge($default, $attributes); |
| 933 | } |
| 934 | } |
| 935 | |
| 936 | $att = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 937 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 938 | foreach ($default as $key => $val) |
| 939 | { |
Alex Bilbie | 773ccc3 | 2012-06-02 11:11:08 +0100 | [diff] [blame] | 940 | if ($key === 'value') |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 941 | { |
Andrey Andreev | 2c24561 | 2015-01-20 15:40:27 +0200 | [diff] [blame] | 942 | $val = html_escape($val); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 943 | } |
Andrey Andreev | 60b9714 | 2012-10-25 16:59:17 +0300 | [diff] [blame] | 944 | elseif ($key === 'name' && ! strlen($default['name'])) |
| 945 | { |
| 946 | continue; |
| 947 | } |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 948 | |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 949 | $att .= $key.'="'.$val.'" '; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | return $att; |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | // ------------------------------------------------------------------------ |
| 957 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 958 | if ( ! function_exists('_attributes_to_string')) |
| 959 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 960 | /** |
| 961 | * Attributes To String |
| 962 | * |
| 963 | * Helper function used by some of the form helpers |
| 964 | * |
| 965 | * @param mixed |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 966 | * @return string |
| 967 | */ |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 968 | function _attributes_to_string($attributes) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 969 | { |
vlakoff | bb8b089 | 2013-07-28 22:35:04 +0200 | [diff] [blame] | 970 | if (empty($attributes)) |
| 971 | { |
| 972 | return ''; |
| 973 | } |
| 974 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 975 | if (is_object($attributes)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 976 | { |
Andrey Andreev | 93a83c7 | 2012-03-26 21:24:02 +0300 | [diff] [blame] | 977 | $attributes = (array) $attributes; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 978 | } |
| 979 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 980 | if (is_array($attributes)) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 981 | { |
Derek Allard | 3241d73 | 2009-09-17 12:17:45 +0000 | [diff] [blame] | 982 | $atts = ''; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 983 | |
Derek Allard | 3241d73 | 2009-09-17 12:17:45 +0000 | [diff] [blame] | 984 | foreach ($attributes as $key => $val) |
| 985 | { |
| 986 | $atts .= ' '.$key.'="'.$val.'"'; |
| 987 | } |
| 988 | |
| 989 | return $atts; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 990 | } |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 991 | |
vlakoff | f746475 | 2013-07-28 22:23:21 +0200 | [diff] [blame] | 992 | if (is_string($attributes)) |
| 993 | { |
Brennan Thompson | 7a772e5 | 2014-02-16 19:22:54 -0700 | [diff] [blame] | 994 | return ' '.$attributes; |
vlakoff | f746475 | 2013-07-28 22:23:21 +0200 | [diff] [blame] | 995 | } |
| 996 | |
vlakoff | ea19bc4 | 2013-07-27 10:07:43 +0200 | [diff] [blame] | 997 | return FALSE; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
| 1001 | // ------------------------------------------------------------------------ |
| 1002 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1003 | if ( ! function_exists('_get_validation_object')) |
| 1004 | { |
Timothy Warren | 01b129a | 2012-04-27 11:36:50 -0400 | [diff] [blame] | 1005 | /** |
| 1006 | * Validation Object |
| 1007 | * |
| 1008 | * Determines what the form validation class was instantiated as, fetches |
| 1009 | * the object and returns it. |
| 1010 | * |
| 1011 | * @return mixed |
| 1012 | */ |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1013 | function &_get_validation_object() |
| 1014 | { |
| 1015 | $CI =& get_instance(); |
| 1016 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1017 | // We set this as a variable since we're returning by reference. |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1018 | $return = FALSE; |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 1019 | |
Andrey Andreev | 519f87a | 2013-07-23 17:16:10 +0300 | [diff] [blame] | 1020 | if (FALSE !== ($object = $CI->load->is_loaded('Form_validation'))) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1021 | { |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1022 | if ( ! isset($CI->$object) OR ! is_object($CI->$object)) |
| 1023 | { |
| 1024 | return $return; |
| 1025 | } |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 1026 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1027 | return $CI->$object; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1028 | } |
Andrey Andreev | 8bf6bb6 | 2012-01-06 16:11:04 +0200 | [diff] [blame] | 1029 | |
Greg Aker | 0c9ee4a | 2011-04-20 09:40:17 -0500 | [diff] [blame] | 1030 | return $return; |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 1031 | } |
| 1032 | } |