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