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