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