blob: f8c6a9dde514bcff4523a382f41c3b94071983e8 [file] [log] [blame]
Andrey Andreevc5536aa2012-11-01 17:33:58 +02001<?php
Derek Allard2067d1a2008-11-13 22:59:24 +00002/**
3 * CodeIgniter
4 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02005 * An open source application development framework for PHP
Derek Allard2067d1a2008-11-13 22:59:24 +00006 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +02007 * This content is released under the MIT License (MIT)
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02008 *
Andrey Andreevfe9309d2015-01-09 17:48:58 +02009 * Copyright (c) 2014 - 2015, British Columbia Institute of Technology
Andrey Andreev8bf6bb62012-01-06 16:11:04 +020010 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020011 * 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 Jonesf4a4bd82011-10-20 12:18:42 -050017 *
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020018 * 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
darwinel871754a2014-02-11 17:34:57 +010031 * @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/)
Andrey Andreevfe9309d2015-01-09 17:48:58 +020032 * @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
Andrey Andreevbdb96ca2014-10-28 00:13:31 +020033 * @license http://opensource.org/licenses/MIT MIT License
34 * @link http://codeigniter.com
35 * @since Version 1.0.0
Andrey Andreevc5536aa2012-11-01 17:33:58 +020036 * @filesource
Derek Allard2067d1a2008-11-13 22:59:24 +000037 */
Andrey Andreevc5536aa2012-11-01 17:33:58 +020038defined('BASEPATH') OR exit('No direct script access allowed');
Derek Allard2067d1a2008-11-13 22:59:24 +000039
Derek Allard2067d1a2008-11-13 22:59:24 +000040/**
41 * CodeIgniter Form Helpers
42 *
43 * @package CodeIgniter
44 * @subpackage Helpers
45 * @category Helpers
Derek Jonesf4a4bd82011-10-20 12:18:42 -050046 * @author EllisLab Dev Team
Derek Allard2067d1a2008-11-13 22:59:24 +000047 * @link http://codeigniter.com/user_guide/helpers/form_helper.html
48 */
49
50// ------------------------------------------------------------------------
51
Derek Allard2067d1a2008-11-13 22:59:24 +000052if ( ! function_exists('form_open'))
53{
Timothy Warren01b129a2012-04-27 11:36:50 -040054 /**
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 */
vlakoffea19bc42013-07-27 10:07:43 +020064 function form_open($action = '', $attributes = array(), $hidden = array())
Derek Allard2067d1a2008-11-13 22:59:24 +000065 {
66 $CI =& get_instance();
67
Andrey Andreevea41c8a2014-02-26 18:31:02 +020068 // 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 }
vlakoffc4f9c622013-07-27 10:08:00 +020073 // If an action is not a full URL then turn it into one
Andrey Andreevea41c8a2014-02-26 18:31:02 +020074 elseif (strpos($action, '://') === FALSE)
vlakoffc4f9c622013-07-27 10:08:00 +020075 {
76 $action = $CI->config->site_url($action);
77 }
vlakoffc4f9c622013-07-27 10:08:00 +020078
vlakoffea19bc42013-07-27 10:07:43 +020079 $attributes = _attributes_to_string($attributes);
80
81 if (stripos($attributes, 'method=') === FALSE)
Andrey Andreev122ca9b2013-07-26 18:16:26 +030082 {
83 $attributes .= ' method="post"';
84 }
Derek Allard2067d1a2008-11-13 22:59:24 +000085
vlakoffea19bc42013-07-27 10:07:43 +020086 if (stripos($attributes, 'accept-charset=') === FALSE)
87 {
88 $attributes .= ' accept-charset="'.strtolower(config_item('charset')).'"';
89 }
90
vlakoffea19bc42013-07-27 10:07:43 +020091 $form = '<form action="'.$action.'"'.$attributes.">\n";
Barry Mienydd671972010-10-04 16:33:58 +020092
Andrey Andreev93a83c72012-03-26 21:24:02 +030093 // Add CSRF field if enabled, but leave it out for GET requests and requests to external websites
Andrey Andreevea41c8a2014-02-26 18:31:02 +020094 if ($CI->config->item('csrf_protection') === TRUE && strpos($action, $CI->config->base_url()) !== FALSE && ! stripos($form, 'method="get"'))
Derek Allard958543a2010-07-22 14:10:26 -040095 {
Greg Aker1f6f0ab2011-04-07 18:24:53 -050096 $hidden[$CI->security->get_csrf_token_name()] = $CI->security->get_csrf_hash();
Greg Aker28b425a2010-09-15 11:43:23 -050097 }
98
Andrey Andreev93b4e782014-03-04 17:48:21 +020099 if (is_array($hidden))
Greg Aker28b425a2010-09-15 11:43:23 -0500100 {
Andrey Andreev93b4e782014-03-04 17:48:21 +0200101 foreach ($hidden as $name => $value)
102 {
Andrey Andreev2c245612015-01-20 15:40:27 +0200103 $form .= '<input type="hidden" name="'.$name.'" value="'.html_escape($value).'" style="display:none;" />'."\n";
Andrey Andreev93b4e782014-03-04 17:48:21 +0200104 }
Derek Allard958543a2010-07-22 14:10:26 -0400105 }
106
Derek Allard2067d1a2008-11-13 22:59:24 +0000107 return $form;
108 }
109}
110
111// ------------------------------------------------------------------------
112
Derek Allard2067d1a2008-11-13 22:59:24 +0000113if ( ! function_exists('form_open_multipart'))
114{
Timothy Warren01b129a2012-04-27 11:36:50 -0400115 /**
116 * Form Declaration - Multipart type
117 *
118 * Creates the opening portion of the form, but with "multipart/form-data".
119 *
120 * @param string the URI segments of the form destination
121 * @param array a key/value pair of attributes
122 * @param array a key/value pair hidden data
123 * @return string
124 */
Ben Edmunds98963b32011-08-20 14:17:16 -0500125 function form_open_multipart($action = '', $attributes = array(), $hidden = array())
Derek Allard2067d1a2008-11-13 22:59:24 +0000126 {
Derek Allard33d4b6a2010-01-17 07:23:00 +0000127 if (is_string($attributes))
128 {
129 $attributes .= ' enctype="multipart/form-data"';
130 }
131 else
132 {
133 $attributes['enctype'] = 'multipart/form-data';
134 }
135
Derek Allard2067d1a2008-11-13 22:59:24 +0000136 return form_open($action, $attributes, $hidden);
137 }
138}
139
140// ------------------------------------------------------------------------
141
Derek Allard2067d1a2008-11-13 22:59:24 +0000142if ( ! function_exists('form_hidden'))
143{
Timothy Warren01b129a2012-04-27 11:36:50 -0400144 /**
145 * Hidden Input Field
146 *
147 * Generates hidden fields. You can pass a simple key/value string or
148 * an associative array with multiple values.
149 *
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200150 * @param mixed $name Field name
151 * @param string $value Field value
152 * @param bool $recursing
Timothy Warren01b129a2012-04-27 11:36:50 -0400153 * @return string
154 */
Robin Sowell57fe4102009-03-26 18:58:46 +0000155 function form_hidden($name, $value = '', $recursing = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000156 {
Robin Sowell57fe4102009-03-26 18:58:46 +0000157 static $form;
158
159 if ($recursing === FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000160 {
Robin Sowell57fe4102009-03-26 18:58:46 +0000161 $form = "\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000162 }
163
Robin Sowell57fe4102009-03-26 18:58:46 +0000164 if (is_array($name))
Derek Allard2067d1a2008-11-13 22:59:24 +0000165 {
Robin Sowell57fe4102009-03-26 18:58:46 +0000166 foreach ($name as $key => $val)
167 {
168 form_hidden($key, $val, TRUE);
169 }
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200170
Robin Sowell57fe4102009-03-26 18:58:46 +0000171 return $form;
172 }
173
174 if ( ! is_array($value))
175 {
Andrey Andreev2c245612015-01-20 15:40:27 +0200176 $form .= '<input type="hidden" name="'.$name.'" value="'.html_escape($value)."\" />\n";
Robin Sowell57fe4102009-03-26 18:58:46 +0000177 }
178 else
179 {
180 foreach ($value as $k => $v)
181 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300182 $k = is_int($k) ? '' : $k;
Robin Sowell57fe4102009-03-26 18:58:46 +0000183 form_hidden($name.'['.$k.']', $v, TRUE);
184 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000185 }
186
187 return $form;
188 }
189}
190
191// ------------------------------------------------------------------------
192
Derek Allard2067d1a2008-11-13 22:59:24 +0000193if ( ! function_exists('form_input'))
194{
Timothy Warren01b129a2012-04-27 11:36:50 -0400195 /**
196 * Text Input Field
197 *
198 * @param mixed
199 * @param string
Adam Jackett664d25a2015-06-03 15:54:54 -0400200 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400201 * @return string
202 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000203 function form_input($data = '', $value = '', $extra = '')
204 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200205 $defaults = array(
206 'type' => 'text',
207 'name' => is_array($data) ? '' : $data,
208 'value' => $value
209 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000210
Adam Jackett664d25a2015-06-03 15:54:54 -0400211 $extra = _attributes_to_string($extra);
212
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200213 return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000214 }
215}
216
217// ------------------------------------------------------------------------
218
Derek Allard2067d1a2008-11-13 22:59:24 +0000219if ( ! function_exists('form_password'))
220{
Timothy Warren01b129a2012-04-27 11:36:50 -0400221 /**
222 * Password Field
223 *
224 * Identical to the input function but adds the "password" type
225 *
226 * @param mixed
227 * @param string
Adam Jackett664d25a2015-06-03 15:54:54 -0400228 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400229 * @return string
230 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000231 function form_password($data = '', $value = '', $extra = '')
232 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200233 is_array($data) OR $data = array('name' => $data);
Derek Allard2067d1a2008-11-13 22:59:24 +0000234 $data['type'] = 'password';
235 return form_input($data, $value, $extra);
236 }
237}
238
239// ------------------------------------------------------------------------
240
Derek Allard2067d1a2008-11-13 22:59:24 +0000241if ( ! function_exists('form_upload'))
242{
Timothy Warren01b129a2012-04-27 11:36:50 -0400243 /**
244 * Upload Field
245 *
246 * Identical to the input function but adds the "file" type
247 *
248 * @param mixed
249 * @param string
Adam Jackett664d25a2015-06-03 15:54:54 -0400250 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400251 * @return string
252 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000253 function form_upload($data = '', $value = '', $extra = '')
254 {
Bo-Yi Wu06ddcf02013-02-18 08:52:05 +0800255 $defaults = array('type' => 'file', 'name' => '');
Andrey Andreev99ba3a22013-02-15 22:42:22 +0200256 is_array($data) OR $data = array('name' => $data);
Derek Allard2067d1a2008-11-13 22:59:24 +0000257 $data['type'] = 'file';
Adam Jackett664d25a2015-06-03 15:54:54 -0400258
259 $extra = _attributes_to_string($extra);
260
Andrey Andreev99ba3a22013-02-15 22:42:22 +0200261 return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000262 }
263}
264
265// ------------------------------------------------------------------------
266
Derek Allard2067d1a2008-11-13 22:59:24 +0000267if ( ! function_exists('form_textarea'))
268{
Timothy Warren01b129a2012-04-27 11:36:50 -0400269 /**
270 * Textarea field
271 *
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200272 * @param mixed $data
273 * @param string $value
Adam Jackett664d25a2015-06-03 15:54:54 -0400274 * @param mixed $extra
Timothy Warren01b129a2012-04-27 11:36:50 -0400275 * @return string
276 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000277 function form_textarea($data = '', $value = '', $extra = '')
278 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200279 $defaults = array(
280 'name' => is_array($data) ? '' : $data,
281 'cols' => '40',
282 'rows' => '10'
283 );
Derek Allard2067d1a2008-11-13 22:59:24 +0000284
285 if ( ! is_array($data) OR ! isset($data['value']))
286 {
287 $val = $value;
288 }
289 else
290 {
Barry Mienydd671972010-10-04 16:33:58 +0200291 $val = $data['value'];
Derek Allard2067d1a2008-11-13 22:59:24 +0000292 unset($data['value']); // textareas don't use the value attribute
293 }
Barry Mienydd671972010-10-04 16:33:58 +0200294
Adam Jackett664d25a2015-06-03 15:54:54 -0400295 $extra = _attributes_to_string($extra);
296
Andrey Andreev2c245612015-01-20 15:40:27 +0200297 return '<textarea '._parse_form_attributes($data, $defaults).$extra.'>'.html_escape($val)."</textarea>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000298 }
299}
300
301// ------------------------------------------------------------------------
302
Derek Jones68788d52010-03-05 10:11:31 -0600303if ( ! function_exists('form_multiselect'))
Derek Jones26399292009-04-08 16:14:17 +0000304{
Timothy Warren01b129a2012-04-27 11:36:50 -0400305 /**
306 * Multi-select menu
307 *
308 * @param string
309 * @param array
310 * @param mixed
Adam Jackett664d25a2015-06-03 15:54:54 -0400311 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400312 * @return string
313 */
Derek Jones26399292009-04-08 16:14:17 +0000314 function form_multiselect($name = '', $options = array(), $selected = array(), $extra = '')
315 {
Adam Jackett664d25a2015-06-03 15:54:54 -0400316 $extra = _attributes_to_string($extra);
317
Derek Jones26399292009-04-08 16:14:17 +0000318 if ( ! strpos($extra, 'multiple'))
319 {
320 $extra .= ' multiple="multiple"';
321 }
Barry Mienydd671972010-10-04 16:33:58 +0200322
Derek Jones26399292009-04-08 16:14:17 +0000323 return form_dropdown($name, $options, $selected, $extra);
324 }
325}
326
327// --------------------------------------------------------------------
328
Derek Allard2067d1a2008-11-13 22:59:24 +0000329if ( ! function_exists('form_dropdown'))
330{
Timothy Warren01b129a2012-04-27 11:36:50 -0400331 /**
332 * Drop-down Menu
333 *
Brennan Thompson40cd6002014-02-14 12:06:38 -0700334 * @param mixed $data
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200335 * @param mixed $options
336 * @param mixed $selected
337 * @param mixed $extra
Timothy Warren01b129a2012-04-27 11:36:50 -0400338 * @return string
339 */
Brennan Thompson40cd6002014-02-14 12:06:38 -0700340 function form_dropdown($data = '', $options = array(), $selected = array(), $extra = '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000341 {
Andrey Andreev15662dd2014-03-06 13:45:33 +0200342 $defaults = array();
Brennan Thompson82c78a92014-02-17 10:02:19 -0700343
Andrey Andreev15662dd2014-03-06 13:45:33 +0200344 if (is_array($data))
Andrey Andreev93a83c72012-03-26 21:24:02 +0300345 {
Andrey Andreev15662dd2014-03-06 13:45:33 +0200346 if (isset($data['selected']))
347 {
348 $selected = $data['selected'];
349 unset($data['selected']); // select tags don't have a selected attribute
350 }
351
352 if (isset($data['options']))
353 {
354 $options = $data['options'];
355 unset($data['options']); // select tags don't use an options attribute
356 }
357 }
358 else
359 {
360 $defaults = array('name' => $data);
Andrey Andreev93a83c72012-03-26 21:24:02 +0300361 }
362
Andrey Andreev582ebcb2012-10-27 00:52:15 +0300363 is_array($selected) OR $selected = array($selected);
Andrey Andreev15662dd2014-03-06 13:45:33 +0200364 is_array($options) OR $options = array($options);
Derek Allard2067d1a2008-11-13 22:59:24 +0000365
366 // If no selected state was submitted we will attempt to set it automatically
Andrey Andreev15662dd2014-03-06 13:45:33 +0200367 if (empty($selected))
Derek Allard2067d1a2008-11-13 22:59:24 +0000368 {
Andrey Andreev15662dd2014-03-06 13:45:33 +0200369 if (is_array($data))
370 {
371 if (isset($data['name'], $_POST[$data['name']]))
372 {
373 $selected = array($_POST[$data['name']]);
374 }
375 }
376 elseif (isset($_POST[$data]))
377 {
378 $selected = array($_POST[$data]);
379 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000380 }
Brennan Thompson82c78a92014-02-17 10:02:19 -0700381
Brennan Thompson1d03ef42014-02-17 12:08:22 -0700382 $extra = _attributes_to_string($extra);
Brennan Thompson82c78a92014-02-17 10:02:19 -0700383
Derek Allard2067d1a2008-11-13 22:59:24 +0000384 $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
Brennan Thompson82c78a92014-02-17 10:02:19 -0700385
Brennan Thompson1d03ef42014-02-17 12:08:22 -0700386 $form = '<select '.rtrim(_parse_form_attributes($data, $defaults)).$extra.$multiple.">\n";
Brennan Thompson82c78a92014-02-17 10:02:19 -0700387
Derek Allard2067d1a2008-11-13 22:59:24 +0000388 foreach ($options as $key => $val)
389 {
390 $key = (string) $key;
Derek Allard2067d1a2008-11-13 22:59:24 +0000391
Andrey Andreev6b114ae2012-07-13 12:05:52 +0300392 if (is_array($val))
Derek Allard78a5fc92009-02-05 16:34:35 +0000393 {
Andrey Andreev6b114ae2012-07-13 12:05:52 +0300394 if (empty($val))
395 {
396 continue;
397 }
398
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200399 $form .= '<optgroup label="'.$key."\">\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000400
Derek Allard78a5fc92009-02-05 16:34:35 +0000401 foreach ($val as $optgroup_key => $optgroup_val)
402 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300403 $sel = in_array($optgroup_key, $selected) ? ' selected="selected"' : '';
Andrey Andreev2c245612015-01-20 15:40:27 +0200404 $form .= '<option value="'.html_escape($optgroup_key).'"'.$sel.'>'
Brennan Thompson82c78a92014-02-17 10:02:19 -0700405 .(string) $optgroup_val."</option>\n";
Derek Allard78a5fc92009-02-05 16:34:35 +0000406 }
407
Andrey Andreev93a83c72012-03-26 21:24:02 +0300408 $form .= "</optgroup>\n";
Derek Allard78a5fc92009-02-05 16:34:35 +0000409 }
410 else
411 {
Andrey Andreev2c245612015-01-20 15:40:27 +0200412 $form .= '<option value="'.html_escape($key).'"'
Brennan Thompson82c78a92014-02-17 10:02:19 -0700413 .(in_array($key, $selected) ? ' selected="selected"' : '').'>'
414 .(string) $val."</option>\n";
Derek Allard78a5fc92009-02-05 16:34:35 +0000415 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000416 }
Brennan Thompson82c78a92014-02-17 10:02:19 -0700417
Andrey Andreev93a83c72012-03-26 21:24:02 +0300418 return $form."</select>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000419 }
420}
421
422// ------------------------------------------------------------------------
423
Derek Allard2067d1a2008-11-13 22:59:24 +0000424if ( ! function_exists('form_checkbox'))
425{
Timothy Warren01b129a2012-04-27 11:36:50 -0400426 /**
427 * Checkbox Field
428 *
429 * @param mixed
430 * @param string
431 * @param bool
Adam Jackett664d25a2015-06-03 15:54:54 -0400432 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400433 * @return string
434 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000435 function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
436 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300437 $defaults = array('type' => 'checkbox', 'name' => ( ! is_array($data) ? $data : ''), 'value' => $value);
Derek Allard2067d1a2008-11-13 22:59:24 +0000438
Andrey Andreev93a83c72012-03-26 21:24:02 +0300439 if (is_array($data) && array_key_exists('checked', $data))
Derek Allard2067d1a2008-11-13 22:59:24 +0000440 {
441 $checked = $data['checked'];
442
Michiel Vugteveen910ff7a2012-06-06 20:03:14 +0200443 if ($checked == FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000444 {
445 unset($data['checked']);
446 }
447 else
448 {
449 $data['checked'] = 'checked';
450 }
451 }
452
Michiel Vugteveen910ff7a2012-06-06 20:03:14 +0200453 if ($checked == TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000454 {
455 $defaults['checked'] = 'checked';
456 }
457 else
458 {
459 unset($defaults['checked']);
460 }
461
Adam Jackett664d25a2015-06-03 15:54:54 -0400462 $extra = _attributes_to_string($extra);
463
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200464 return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000465 }
466}
467
468// ------------------------------------------------------------------------
469
Derek Allard2067d1a2008-11-13 22:59:24 +0000470if ( ! function_exists('form_radio'))
471{
Timothy Warren01b129a2012-04-27 11:36:50 -0400472 /**
473 * Radio Button
474 *
475 * @param mixed
476 * @param string
477 * @param bool
Adam Jackett664d25a2015-06-03 15:54:54 -0400478 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400479 * @return string
480 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000481 function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
482 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200483 is_array($data) OR $data = array('name' => $data);
Derek Allard2067d1a2008-11-13 22:59:24 +0000484 $data['type'] = 'radio';
Adam Jackett664d25a2015-06-03 15:54:54 -0400485
Derek Allard2067d1a2008-11-13 22:59:24 +0000486 return form_checkbox($data, $value, $checked, $extra);
487 }
488}
489
490// ------------------------------------------------------------------------
491
Derek Allard2067d1a2008-11-13 22:59:24 +0000492if ( ! function_exists('form_submit'))
Barry Mienydd671972010-10-04 16:33:58 +0200493{
Timothy Warren01b129a2012-04-27 11:36:50 -0400494 /**
495 * Submit Button
496 *
497 * @param mixed
498 * @param string
Adam Jackett664d25a2015-06-03 15:54:54 -0400499 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400500 * @return string
501 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000502 function form_submit($data = '', $value = '', $extra = '')
503 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200504 $defaults = array(
505 'type' => 'submit',
506 'name' => is_array($data) ? '' : $data,
507 'value' => $value
508 );
509
Adam Jackett664d25a2015-06-03 15:54:54 -0400510 $extra = _attributes_to_string($extra);
511
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200512 return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000513 }
514}
515
516// ------------------------------------------------------------------------
517
Derek Allard2067d1a2008-11-13 22:59:24 +0000518if ( ! function_exists('form_reset'))
519{
Timothy Warren01b129a2012-04-27 11:36:50 -0400520 /**
521 * Reset Button
522 *
523 * @param mixed
524 * @param string
Adam Jackett664d25a2015-06-03 15:54:54 -0400525 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400526 * @return string
527 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000528 function form_reset($data = '', $value = '', $extra = '')
529 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200530 $defaults = array(
531 'type' => 'reset',
532 'name' => is_array($data) ? '' : $data,
533 'value' => $value
534 );
535
Adam Jackett664d25a2015-06-03 15:54:54 -0400536 $extra = _attributes_to_string($extra);
537
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200538 return '<input '._parse_form_attributes($data, $defaults).$extra." />\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000539 }
540}
541
542// ------------------------------------------------------------------------
543
Derek Allard2067d1a2008-11-13 22:59:24 +0000544if ( ! function_exists('form_button'))
545{
Timothy Warren01b129a2012-04-27 11:36:50 -0400546 /**
547 * Form Button
548 *
549 * @param mixed
550 * @param string
Adam Jackett664d25a2015-06-03 15:54:54 -0400551 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400552 * @return string
553 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000554 function form_button($data = '', $content = '', $extra = '')
555 {
Andrey Andreevea41c8a2014-02-26 18:31:02 +0200556 $defaults = array(
557 'name' => is_array($data) ? '' : $data,
558 'type' => 'button'
559 );
560
Andrey Andreev93a83c72012-03-26 21:24:02 +0300561 if (is_array($data) && isset($data['content']))
Derek Allard2067d1a2008-11-13 22:59:24 +0000562 {
563 $content = $data['content'];
564 unset($data['content']); // content is not an attribute
565 }
566
Adam Jackett664d25a2015-06-03 15:54:54 -0400567 $extra = _attributes_to_string($extra);
568
Andrey Andreev8bf6bb62012-01-06 16:11:04 +0200569 return '<button '._parse_form_attributes($data, $defaults).$extra.'>'.$content."</button>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000570 }
571}
572
573// ------------------------------------------------------------------------
574
Derek Allard2067d1a2008-11-13 22:59:24 +0000575if ( ! function_exists('form_label'))
576{
Timothy Warren01b129a2012-04-27 11:36:50 -0400577 /**
578 * Form Label Tag
579 *
580 * @param string The text to appear onscreen
581 * @param string The id the label applies to
582 * @param string Additional attributes
583 * @return string
584 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000585 function form_label($label_text = '', $id = '', $attributes = array())
586 {
587
588 $label = '<label';
589
Alex Bilbie773ccc32012-06-02 11:11:08 +0100590 if ($id !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000591 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300592 $label .= ' for="'.$id.'"';
Derek Allard2067d1a2008-11-13 22:59:24 +0000593 }
594
Andrey Andreev93a83c72012-03-26 21:24:02 +0300595 if (is_array($attributes) && count($attributes) > 0)
Derek Allard2067d1a2008-11-13 22:59:24 +0000596 {
597 foreach ($attributes as $key => $val)
598 {
599 $label .= ' '.$key.'="'.$val.'"';
600 }
601 }
602
Andrey Andreev93a83c72012-03-26 21:24:02 +0300603 return $label.'>'.$label_text.'</label>';
Derek Allard2067d1a2008-11-13 22:59:24 +0000604 }
605}
606
607// ------------------------------------------------------------------------
Timothy Warren01b129a2012-04-27 11:36:50 -0400608
Derek Allard2067d1a2008-11-13 22:59:24 +0000609if ( ! function_exists('form_fieldset'))
610{
Timothy Warren01b129a2012-04-27 11:36:50 -0400611 /**
612 * Fieldset Tag
613 *
614 * Used to produce <fieldset><legend>text</legend>. To close fieldset
615 * use form_fieldset_close()
616 *
617 * @param string The legend text
vlakoffea19bc42013-07-27 10:07:43 +0200618 * @param array Additional attributes
Timothy Warren01b129a2012-04-27 11:36:50 -0400619 * @return string
620 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000621 function form_fieldset($legend_text = '', $attributes = array())
622 {
vlakoffea19bc42013-07-27 10:07:43 +0200623 $fieldset = '<fieldset'._attributes_to_string($attributes).">\n";
Alex Bilbie773ccc32012-06-02 11:11:08 +0100624 if ($legend_text !== '')
Derek Allard2067d1a2008-11-13 22:59:24 +0000625 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300626 return $fieldset.'<legend>'.$legend_text."</legend>\n";
Derek Allard2067d1a2008-11-13 22:59:24 +0000627 }
628
629 return $fieldset;
630 }
631}
632
633// ------------------------------------------------------------------------
634
Derek Allard2067d1a2008-11-13 22:59:24 +0000635if ( ! function_exists('form_fieldset_close'))
636{
Timothy Warren01b129a2012-04-27 11:36:50 -0400637 /**
638 * Fieldset Close Tag
639 *
640 * @param string
641 * @return string
642 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000643 function form_fieldset_close($extra = '')
644 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300645 return '</fieldset>'.$extra;
Derek Allard2067d1a2008-11-13 22:59:24 +0000646 }
647}
648
649// ------------------------------------------------------------------------
650
Derek Allard2067d1a2008-11-13 22:59:24 +0000651if ( ! function_exists('form_close'))
652{
Timothy Warren01b129a2012-04-27 11:36:50 -0400653 /**
654 * Form Close Tag
655 *
656 * @param string
657 * @return string
658 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000659 function form_close($extra = '')
660 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300661 return '</form>'.$extra;
Derek Allard2067d1a2008-11-13 22:59:24 +0000662 }
663}
664
665// ------------------------------------------------------------------------
666
Derek Allard2067d1a2008-11-13 22:59:24 +0000667if ( ! function_exists('form_prep'))
668{
Timothy Warren01b129a2012-04-27 11:36:50 -0400669 /**
670 * Form Prep
671 *
672 * Formats text so that it can be safely placed in a form field in the event it has HTML tags.
673 *
Andrey Andreev2c245612015-01-20 15:40:27 +0200674 * @deprecated 3.0.0 An alias for html_escape()
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200675 * @param string|string[] $str Value to escape
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200676 * @return string|string[] Escaped values
Timothy Warren01b129a2012-04-27 11:36:50 -0400677 */
Andrey Andreev2c245612015-01-20 15:40:27 +0200678 function form_prep($str)
Derek Allard2067d1a2008-11-13 22:59:24 +0000679 {
Andrey Andreev2c245612015-01-20 15:40:27 +0200680 return html_escape($str, TRUE);
Derek Allard2067d1a2008-11-13 22:59:24 +0000681 }
682}
683
684// ------------------------------------------------------------------------
685
Derek Allard2067d1a2008-11-13 22:59:24 +0000686if ( ! function_exists('set_value'))
687{
Timothy Warren01b129a2012-04-27 11:36:50 -0400688 /**
689 * Form Value
690 *
691 * Grabs a value from the POST array for the specified field so you can
692 * re-populate an input field or textarea. If Form Validation
693 * is active it retrieves the info from the validation class
694 *
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200695 * @param string $field Field name
696 * @param string $default Default value
Adrian Voicufa61fb22015-02-05 15:46:12 +0200697 * @param bool $html_escape Whether to escape HTML special characters or not
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200698 * @return string
Timothy Warren01b129a2012-04-27 11:36:50 -0400699 */
Adrian Voicu86e6a192015-02-05 13:51:26 +0200700 function set_value($field, $default = '', $html_escape = TRUE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000701 {
nisheeth-barthwal77236e02013-03-25 23:42:36 +0530702 $CI =& get_instance();
Derek Allard2067d1a2008-11-13 22:59:24 +0000703
nisheeth-barthwal47ea5a82013-03-26 18:57:28 +0530704 $value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
705 ? $CI->form_validation->set_value($field, $default)
706 : $CI->input->post($field, FALSE);
Andrey Andreev7df66342015-02-05 15:58:09 +0200707
Adrian Voicu86e6a192015-02-05 13:51:26 +0200708 isset($value) OR $value = $default;
709 return ($html_escape) ? html_escape($value) : $value;
Derek Allard2067d1a2008-11-13 22:59:24 +0000710 }
711}
712
713// ------------------------------------------------------------------------
714
Derek Allard2067d1a2008-11-13 22:59:24 +0000715if ( ! function_exists('set_select'))
716{
Timothy Warren01b129a2012-04-27 11:36:50 -0400717 /**
718 * Set Select
719 *
720 * Let's you set the selected value of a <select> menu via data in the POST array.
721 * If Form Validation is active it retrieves the info from the validation class
722 *
723 * @param string
724 * @param string
725 * @param bool
726 * @return string
727 */
Andrey Andreev2c245612015-01-20 15:40:27 +0200728 function set_select($field, $value = '', $default = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000729 {
Andrey Andreev67f6a5e2013-09-13 16:21:31 +0300730 $CI =& get_instance();
Derek Allard2067d1a2008-11-13 22:59:24 +0000731
Andrey Andreev67f6a5e2013-09-13 16:21:31 +0300732 if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
Derek Allard2067d1a2008-11-13 22:59:24 +0000733 {
Andrey Andreev67f6a5e2013-09-13 16:21:31 +0300734 return $CI->form_validation->set_select($field, $value, $default);
735 }
736 elseif (($input = $CI->input->post($field, FALSE)) === NULL)
737 {
738 return ($default === TRUE) ? ' selected="selected"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000739 }
Andrey Andreeva587a932013-10-23 19:57:46 +0300740
741 $value = (string) $value;
742 if (is_array($input))
Andrey Andreevd3b7e242013-09-13 18:36:29 +0300743 {
Andrey Andreeva587a932013-10-23 19:57:46 +0300744 // Note: in_array('', array(0)) returns TRUE, do not use it
745 foreach ($input as &$v)
746 {
747 if ($value === $v)
748 {
749 return ' selected="selected"';
750 }
751 }
752
753 return '';
Andrey Andreevd3b7e242013-09-13 18:36:29 +0300754 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000755
Andrey Andreevd3b7e242013-09-13 18:36:29 +0300756 return ($input === $value) ? ' selected="selected"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000757 }
758}
759
760// ------------------------------------------------------------------------
761
Derek Allard2067d1a2008-11-13 22:59:24 +0000762if ( ! function_exists('set_checkbox'))
763{
Timothy Warren01b129a2012-04-27 11:36:50 -0400764 /**
765 * Set Checkbox
766 *
767 * Let's you set the selected value of a checkbox via the value in the POST array.
768 * If Form Validation is active it retrieves the info from the validation class
769 *
770 * @param string
771 * @param string
772 * @param bool
773 * @return string
774 */
Andrey Andreev2c245612015-01-20 15:40:27 +0200775 function set_checkbox($field, $value = '', $default = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000776 {
Andrey Andreevae50f552013-09-13 16:17:41 +0300777 $CI =& get_instance();
Derek Allard2067d1a2008-11-13 22:59:24 +0000778
Andrey Andreevae50f552013-09-13 16:17:41 +0300779 if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
Barry Mienydd671972010-10-04 16:33:58 +0200780 {
Andrey Andreevae50f552013-09-13 16:17:41 +0300781 return $CI->form_validation->set_checkbox($field, $value, $default);
782 }
783 elseif (($input = $CI->input->post($field, FALSE)) === NULL)
784 {
785 return ($default === TRUE) ? ' checked="checked"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000786 }
Andrey Andreeva587a932013-10-23 19:57:46 +0300787
788 $value = (string) $value;
789 if (is_array($input))
Andrey Andreeve8a23a52013-09-13 18:29:29 +0300790 {
Andrey Andreeva587a932013-10-23 19:57:46 +0300791 // Note: in_array('', array(0)) returns TRUE, do not use it
792 foreach ($input as &$v)
793 {
794 if ($value === $v)
795 {
796 return ' checked="checked"';
797 }
798 }
799
800 return '';
Andrey Andreeve8a23a52013-09-13 18:29:29 +0300801 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000802
Andrey Andreevae50f552013-09-13 16:17:41 +0300803 return ($input === $value) ? ' checked="checked"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000804 }
805}
806
807// ------------------------------------------------------------------------
808
Derek Allard2067d1a2008-11-13 22:59:24 +0000809if ( ! function_exists('set_radio'))
810{
Timothy Warren01b129a2012-04-27 11:36:50 -0400811 /**
812 * Set Radio
813 *
814 * Let's you set the selected value of a radio field via info in the POST array.
815 * If Form Validation is active it retrieves the info from the validation class
816 *
Andrey Andreevae50f552013-09-13 16:17:41 +0300817 * @param string $field
818 * @param string $value
819 * @param bool $default
Timothy Warren01b129a2012-04-27 11:36:50 -0400820 * @return string
821 */
Andrey Andreev2c245612015-01-20 15:40:27 +0200822 function set_radio($field, $value = '', $default = FALSE)
Derek Allard2067d1a2008-11-13 22:59:24 +0000823 {
Andrey Andreevae50f552013-09-13 16:17:41 +0300824 $CI =& get_instance();
Derek Allard2067d1a2008-11-13 22:59:24 +0000825
Andrey Andreevae50f552013-09-13 16:17:41 +0300826 if (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
Derek Allard2067d1a2008-11-13 22:59:24 +0000827 {
Andrey Andreevae50f552013-09-13 16:17:41 +0300828 return $CI->form_validation->set_radio($field, $value, $default);
829 }
830 elseif (($input = $CI->input->post($field, FALSE)) === NULL)
831 {
832 return ($default === TRUE) ? ' checked="checked"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000833 }
834
Andrey Andreeva587a932013-10-23 19:57:46 +0300835 return ($input === (string) $value) ? ' checked="checked"' : '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000836 }
837}
838
839// ------------------------------------------------------------------------
840
Derek Allard2067d1a2008-11-13 22:59:24 +0000841if ( ! function_exists('form_error'))
842{
Timothy Warren01b129a2012-04-27 11:36:50 -0400843 /**
844 * Form Error
845 *
846 * Returns the error for a specific form field. This is a helper for the
847 * form validation class.
848 *
849 * @param string
850 * @param string
851 * @param string
852 * @return string
853 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000854 function form_error($field = '', $prefix = '', $suffix = '')
855 {
856 if (FALSE === ($OBJ =& _get_validation_object()))
857 {
858 return '';
859 }
860
861 return $OBJ->error($field, $prefix, $suffix);
862 }
863}
864
865// ------------------------------------------------------------------------
866
Derek Allard2067d1a2008-11-13 22:59:24 +0000867if ( ! function_exists('validation_errors'))
868{
Timothy Warren01b129a2012-04-27 11:36:50 -0400869 /**
870 * Validation Error String
871 *
872 * Returns all the errors associated with a form submission. This is a helper
873 * function for the form validation class.
874 *
875 * @param string
876 * @param string
877 * @return string
878 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000879 function validation_errors($prefix = '', $suffix = '')
880 {
881 if (FALSE === ($OBJ =& _get_validation_object()))
Greg Akerc83bea62011-04-23 12:12:57 -0500882 {
Derek Allard2067d1a2008-11-13 22:59:24 +0000883 return '';
884 }
885
886 return $OBJ->error_string($prefix, $suffix);
887 }
888}
889
890// ------------------------------------------------------------------------
891
Derek Allard2067d1a2008-11-13 22:59:24 +0000892if ( ! function_exists('_parse_form_attributes'))
893{
Timothy Warren01b129a2012-04-27 11:36:50 -0400894 /**
895 * Parse the form attributes
896 *
897 * Helper function used by some of the form helpers
898 *
Andrey Andreev7c4d1062012-11-01 15:14:34 +0200899 * @param array $attributes List of attributes
900 * @param array $default Default values
Timothy Warren01b129a2012-04-27 11:36:50 -0400901 * @return string
902 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000903 function _parse_form_attributes($attributes, $default)
904 {
905 if (is_array($attributes))
906 {
907 foreach ($default as $key => $val)
908 {
909 if (isset($attributes[$key]))
910 {
911 $default[$key] = $attributes[$key];
912 unset($attributes[$key]);
913 }
914 }
915
916 if (count($attributes) > 0)
917 {
918 $default = array_merge($default, $attributes);
919 }
920 }
921
922 $att = '';
Barry Mienydd671972010-10-04 16:33:58 +0200923
Derek Allard2067d1a2008-11-13 22:59:24 +0000924 foreach ($default as $key => $val)
925 {
Alex Bilbie773ccc32012-06-02 11:11:08 +0100926 if ($key === 'value')
Derek Allard2067d1a2008-11-13 22:59:24 +0000927 {
Andrey Andreev2c245612015-01-20 15:40:27 +0200928 $val = html_escape($val);
Derek Allard2067d1a2008-11-13 22:59:24 +0000929 }
Andrey Andreev60b97142012-10-25 16:59:17 +0300930 elseif ($key === 'name' && ! strlen($default['name']))
931 {
932 continue;
933 }
Derek Allard2067d1a2008-11-13 22:59:24 +0000934
Andrey Andreev93a83c72012-03-26 21:24:02 +0300935 $att .= $key.'="'.$val.'" ';
Derek Allard2067d1a2008-11-13 22:59:24 +0000936 }
937
938 return $att;
939 }
940}
941
942// ------------------------------------------------------------------------
943
Derek Allard2067d1a2008-11-13 22:59:24 +0000944if ( ! function_exists('_attributes_to_string'))
945{
Timothy Warren01b129a2012-04-27 11:36:50 -0400946 /**
947 * Attributes To String
948 *
949 * Helper function used by some of the form helpers
950 *
951 * @param mixed
Timothy Warren01b129a2012-04-27 11:36:50 -0400952 * @return string
953 */
vlakoffea19bc42013-07-27 10:07:43 +0200954 function _attributes_to_string($attributes)
Derek Allard2067d1a2008-11-13 22:59:24 +0000955 {
vlakoffbb8b0892013-07-28 22:35:04 +0200956 if (empty($attributes))
957 {
958 return '';
959 }
960
vlakoffea19bc42013-07-27 10:07:43 +0200961 if (is_object($attributes))
Derek Allard2067d1a2008-11-13 22:59:24 +0000962 {
Andrey Andreev93a83c72012-03-26 21:24:02 +0300963 $attributes = (array) $attributes;
Derek Allard2067d1a2008-11-13 22:59:24 +0000964 }
965
vlakoffea19bc42013-07-27 10:07:43 +0200966 if (is_array($attributes))
Derek Allard2067d1a2008-11-13 22:59:24 +0000967 {
Derek Allard3241d732009-09-17 12:17:45 +0000968 $atts = '';
Derek Allard2067d1a2008-11-13 22:59:24 +0000969
Derek Allard3241d732009-09-17 12:17:45 +0000970 foreach ($attributes as $key => $val)
971 {
972 $atts .= ' '.$key.'="'.$val.'"';
973 }
974
975 return $atts;
Derek Allard2067d1a2008-11-13 22:59:24 +0000976 }
vlakoffea19bc42013-07-27 10:07:43 +0200977
vlakofff7464752013-07-28 22:23:21 +0200978 if (is_string($attributes))
979 {
Brennan Thompson7a772e52014-02-16 19:22:54 -0700980 return ' '.$attributes;
vlakofff7464752013-07-28 22:23:21 +0200981 }
982
vlakoffea19bc42013-07-27 10:07:43 +0200983 return FALSE;
Derek Allard2067d1a2008-11-13 22:59:24 +0000984 }
985}
986
987// ------------------------------------------------------------------------
988
Derek Allard2067d1a2008-11-13 22:59:24 +0000989if ( ! function_exists('_get_validation_object'))
990{
Timothy Warren01b129a2012-04-27 11:36:50 -0400991 /**
992 * Validation Object
993 *
994 * Determines what the form validation class was instantiated as, fetches
995 * the object and returns it.
996 *
997 * @return mixed
998 */
Derek Allard2067d1a2008-11-13 22:59:24 +0000999 function &_get_validation_object()
1000 {
1001 $CI =& get_instance();
1002
Greg Aker0c9ee4a2011-04-20 09:40:17 -05001003 // We set this as a variable since we're returning by reference.
Derek Allard2067d1a2008-11-13 22:59:24 +00001004 $return = FALSE;
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02001005
Andrey Andreev519f87a2013-07-23 17:16:10 +03001006 if (FALSE !== ($object = $CI->load->is_loaded('Form_validation')))
Derek Allard2067d1a2008-11-13 22:59:24 +00001007 {
Greg Aker0c9ee4a2011-04-20 09:40:17 -05001008 if ( ! isset($CI->$object) OR ! is_object($CI->$object))
1009 {
1010 return $return;
1011 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02001012
Greg Aker0c9ee4a2011-04-20 09:40:17 -05001013 return $CI->$object;
Derek Allard2067d1a2008-11-13 22:59:24 +00001014 }
Andrey Andreev8bf6bb62012-01-06 16:11:04 +02001015
Greg Aker0c9ee4a2011-04-20 09:40:17 -05001016 return $return;
Derek Allard2067d1a2008-11-13 22:59:24 +00001017 }
1018}