blob: 541ab844af54fd7a8340382bb3c30e604262960a [file] [log] [blame]
Derek Allardf3e8a352008-01-04 14:30:38 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * CodeIgniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
Derek Allard3d879d52008-01-18 19:41:32 +00008 * @author ExpressionEngine Dev Team
Derek Allardf3e8a352008-01-04 14:30:38 +00009 * @copyright Copyright (c) 2006, EllisLab, Inc.
Derek Jones7a9193a2008-01-21 18:39:20 +000010 * @license http://codeigniter.com/user_guide/license.html
11 * @link http://codeigniter.com
Derek Allardf3e8a352008-01-04 14:30:38 +000012 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * CodeIgniter Form Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
Derek Allard3d879d52008-01-18 19:41:32 +000024 * @author ExpressionEngine Dev Team
Derek Jones7a9193a2008-01-21 18:39:20 +000025 * @link http://codeigniter.com/user_guide/helpers/form_helper.html
Derek Allardf3e8a352008-01-04 14:30:38 +000026 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Form Declaration
32 *
33 * Creates the opening portion of the form.
34 *
35 * @access public
36 * @param string the URI segments of the form destination
37 * @param array a key/value pair of attributes
38 * @param array a key/value pair hidden data
39 * @return string
40 */
Derek Jones269b9422008-01-28 21:00:20 +000041if (! function_exists('form_open'))
Derek Allardf3e8a352008-01-04 14:30:38 +000042{
Derek Jones269b9422008-01-28 21:00:20 +000043 function form_open($action = '', $attributes = array(), $hidden = array())
Derek Allardf3e8a352008-01-04 14:30:38 +000044 {
Derek Jones269b9422008-01-28 21:00:20 +000045 $CI =& get_instance();
46
47 $action = ( strpos($action, '://') === FALSE) ? $CI->config->site_url($action) : $action;
48
49 $form = '<form action="'.$action.'"';
Derek Allardf3e8a352008-01-04 14:30:38 +000050
Derek Allard73274992008-05-05 16:39:18 +000051 if (! isset($attributes['method']))
Derek Allardf3e8a352008-01-04 14:30:38 +000052 {
Derek Jones269b9422008-01-28 21:00:20 +000053 $form .= ' method="post"';
Derek Allardf3e8a352008-01-04 14:30:38 +000054 }
Derek Allardf3e8a352008-01-04 14:30:38 +000055
Derek Jones269b9422008-01-28 21:00:20 +000056 if (is_array($attributes) AND count($attributes) > 0)
57 {
58 foreach ($attributes as $key => $val)
59 {
60 $form .= ' '.$key.'="'.$val.'"';
61 }
62 }
63
64 $form .= '>';
Derek Allardf3e8a352008-01-04 14:30:38 +000065
Derek Jones269b9422008-01-28 21:00:20 +000066 if (is_array($hidden) AND count($hidden > 0))
67 {
68 $form .= form_hidden($hidden);
69 }
Derek Allardf3e8a352008-01-04 14:30:38 +000070
Derek Jones269b9422008-01-28 21:00:20 +000071 return $form;
72 }
Derek Allardf3e8a352008-01-04 14:30:38 +000073}
74
75// ------------------------------------------------------------------------
76
77/**
78 * Form Declaration - Multipart type
79 *
80 * Creates the opening portion of the form, but with "multipart/form-data".
81 *
82 * @access public
83 * @param string the URI segments of the form destination
84 * @param array a key/value pair of attributes
85 * @param array a key/value pair hidden data
86 * @return string
87 */
Derek Jones269b9422008-01-28 21:00:20 +000088if (! function_exists('form_open_multipart'))
Derek Allardf3e8a352008-01-04 14:30:38 +000089{
Derek Jones269b9422008-01-28 21:00:20 +000090 function form_open_multipart($action, $attributes = array(), $hidden = array())
91 {
92 $attributes['enctype'] = 'multipart/form-data';
93 return form_open($action, $attributes, $hidden);
94 }
Derek Allardf3e8a352008-01-04 14:30:38 +000095}
96
97// ------------------------------------------------------------------------
98
99/**
100 * Hidden Input Field
101 *
102 * Generates hidden fields. You can pass a simple key/value string or an associative
103 * array with multiple values.
104 *
105 * @access public
106 * @param mixed
107 * @param string
108 * @return string
109 */
Derek Jones269b9422008-01-28 21:00:20 +0000110if (! function_exists('form_hidden'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000111{
Derek Jones269b9422008-01-28 21:00:20 +0000112 function form_hidden($name, $value = '')
Derek Allardf3e8a352008-01-04 14:30:38 +0000113 {
Derek Allard73274992008-05-05 16:39:18 +0000114 if (! is_array($name))
Derek Jones269b9422008-01-28 21:00:20 +0000115 {
116 return '<input type="hidden" name="'.$name.'" value="'.form_prep($value).'" />';
117 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000118
Derek Jones269b9422008-01-28 21:00:20 +0000119 $form = '';
120 foreach ($name as $name => $value)
121 {
122 $form .= '<input type="hidden" name="'.$name.'" value="'.form_prep($value).'" />';
123 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000124
Derek Jones269b9422008-01-28 21:00:20 +0000125 return $form;
126 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000127}
128
129// ------------------------------------------------------------------------
130
131/**
132 * Text Input Field
133 *
134 * @access public
135 * @param mixed
136 * @param string
137 * @param string
138 * @return string
139 */
Derek Jones269b9422008-01-28 21:00:20 +0000140if (! function_exists('form_input'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000141{
Derek Jones269b9422008-01-28 21:00:20 +0000142 function form_input($data = '', $value = '', $extra = '')
143 {
Derek Allard73274992008-05-05 16:39:18 +0000144 $defaults = array('type' => 'text', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value, 'maxlength' => '500', 'size' => '50');
Derek Allardf3e8a352008-01-04 14:30:38 +0000145
Derek Jones269b9422008-01-28 21:00:20 +0000146 return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
147 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000148}
149
150// ------------------------------------------------------------------------
151
152/**
153 * Password Field
154 *
155 * Identical to the input function but adds the "password" type
156 *
157 * @access public
158 * @param mixed
159 * @param string
160 * @param string
161 * @return string
162 */
Derek Jones269b9422008-01-28 21:00:20 +0000163if (! function_exists('form_password'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000164{
Derek Jones269b9422008-01-28 21:00:20 +0000165 function form_password($data = '', $value = '', $extra = '')
Derek Allardf3e8a352008-01-04 14:30:38 +0000166 {
Derek Allard73274992008-05-05 16:39:18 +0000167 if (! is_array($data))
Derek Jones269b9422008-01-28 21:00:20 +0000168 {
169 $data = array('name' => $data);
170 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000171
Derek Jones269b9422008-01-28 21:00:20 +0000172 $data['type'] = 'password';
173 return form_input($data, $value, $extra);
174 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000175}
176
177// ------------------------------------------------------------------------
178
179/**
180 * Upload Field
181 *
182 * Identical to the input function but adds the "file" type
183 *
184 * @access public
185 * @param mixed
186 * @param string
187 * @param string
188 * @return string
189 */
Derek Jones269b9422008-01-28 21:00:20 +0000190if (! function_exists('form_upload'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000191{
Derek Jones269b9422008-01-28 21:00:20 +0000192 function form_upload($data = '', $value = '', $extra = '')
Derek Allardf3e8a352008-01-04 14:30:38 +0000193 {
Derek Allard73274992008-05-05 16:39:18 +0000194 if (! is_array($data))
Derek Jones269b9422008-01-28 21:00:20 +0000195 {
196 $data = array('name' => $data);
197 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000198
Derek Jones269b9422008-01-28 21:00:20 +0000199 $data['type'] = 'file';
200 return form_input($data, $value, $extra);
201 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000202}
203
204// ------------------------------------------------------------------------
205
206/**
207 * Textarea field
208 *
209 * @access public
210 * @param mixed
211 * @param string
212 * @param string
213 * @return string
214 */
Derek Jones269b9422008-01-28 21:00:20 +0000215if (! function_exists('form_textarea'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000216{
Derek Jones269b9422008-01-28 21:00:20 +0000217 function form_textarea($data = '', $value = '', $extra = '')
218 {
Derek Allard73274992008-05-05 16:39:18 +0000219 $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'cols' => '90', 'rows' => '12');
Derek Allardf3e8a352008-01-04 14:30:38 +0000220
Derek Allard73274992008-05-05 16:39:18 +0000221 if (! is_array($data) OR ! isset($data['value']))
Derek Jones269b9422008-01-28 21:00:20 +0000222 {
223 $val = $value;
224 }
225 else
226 {
227 $val = $data['value'];
228 unset($data['value']); // textareas don't use the value attribute
229 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000230
Derek Jones269b9422008-01-28 21:00:20 +0000231 return "<textarea ".parse_form_attributes($data, $defaults).$extra.">".$val."</textarea>\n";
232 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000233}
234
235// ------------------------------------------------------------------------
236
237/**
238 * Drop-down Menu
239 *
240 * @access public
241 * @param string
242 * @param array
243 * @param string
244 * @param string
245 * @return string
246 */
Derek Jones269b9422008-01-28 21:00:20 +0000247if (! function_exists('form_dropdown'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000248{
Derek Jones269b9422008-01-28 21:00:20 +0000249 function form_dropdown($name = '', $options = array(), $selected = array(), $extra = '')
Derek Allard4021b512008-01-04 22:26:12 +0000250 {
Derek Allard73274992008-05-05 16:39:18 +0000251 if (! is_array($selected))
Derek Jones269b9422008-01-28 21:00:20 +0000252 {
253 $selected = array($selected);
254 }
Derek Allard4021b512008-01-04 22:26:12 +0000255
Derek Jones269b9422008-01-28 21:00:20 +0000256 if ($extra != '') $extra = ' '.$extra;
Derek Allardf8f05702008-01-18 14:39:23 +0000257
Derek Jones269b9422008-01-28 21:00:20 +0000258 $multiple = (count($selected) > 1 && strpos($extra, 'multiple') === FALSE) ? ' multiple="multiple"' : '';
Derek Allard4021b512008-01-04 22:26:12 +0000259
Derek Jones269b9422008-01-28 21:00:20 +0000260 $form = '<select name="'.$name.'"'.$extra.$multiple.">\n";
Derek Allardf3e8a352008-01-04 14:30:38 +0000261
Derek Jones269b9422008-01-28 21:00:20 +0000262 foreach ($options as $key => $val)
263 {
264 $key = (string) $key;
265 $val = (string) $val;
Derek Allardf3e8a352008-01-04 14:30:38 +0000266
Derek Jones269b9422008-01-28 21:00:20 +0000267 $sel = (in_array($key, $selected))?' selected="selected"':'';
Derek Allardf3e8a352008-01-04 14:30:38 +0000268
Derek Jones269b9422008-01-28 21:00:20 +0000269 $form .= '<option value="'.$key.'"'.$sel.'>'.$val."</option>\n";
270 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000271
Derek Jones269b9422008-01-28 21:00:20 +0000272 $form .= '</select>';
Derek Allardf3e8a352008-01-04 14:30:38 +0000273
Derek Jones269b9422008-01-28 21:00:20 +0000274 return $form;
275 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000276}
277
278// ------------------------------------------------------------------------
279
280/**
281 * Checkbox Field
282 *
283 * @access public
284 * @param mixed
285 * @param string
286 * @param bool
287 * @param string
288 * @return string
289 */
Derek Jones269b9422008-01-28 21:00:20 +0000290if (! function_exists('form_checkbox'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000291{
Derek Allardde7320b2008-05-06 13:51:02 +0000292 function form_checkbox($data = '', $value = '', $checked = FALSE, $extra = '')
Derek Allardf3e8a352008-01-04 14:30:38 +0000293 {
Derek Allard73274992008-05-05 16:39:18 +0000294 $defaults = array('type' => 'checkbox', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value);
Derek Allardf3e8a352008-01-04 14:30:38 +0000295
Derek Jones269b9422008-01-28 21:00:20 +0000296 if (is_array($data) AND array_key_exists('checked', $data))
297 {
298 $checked = $data['checked'];
299
300 if ($checked == FALSE)
301 {
302 unset($data['checked']);
303 }
304 else
305 {
306 $data['checked'] = 'checked';
307 }
308 }
309
310 if ($checked == TRUE)
311 $defaults['checked'] = 'checked';
312 else
313 unset($defaults['checked']);
Derek Allardf3e8a352008-01-04 14:30:38 +0000314
Derek Jones269b9422008-01-28 21:00:20 +0000315 return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
316 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000317}
318
319// ------------------------------------------------------------------------
320
321/**
322 * Radio Button
323 *
324 * @access public
325 * @param mixed
326 * @param string
327 * @param bool
328 * @param string
329 * @return string
330 */
Derek Jones269b9422008-01-28 21:00:20 +0000331if (! function_exists('form_radio'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000332{
Derek Allardde7320b2008-05-06 13:51:02 +0000333 function form_radio($data = '', $value = '', $checked = FALSE, $extra = '')
Derek Jones269b9422008-01-28 21:00:20 +0000334 {
Derek Allard73274992008-05-05 16:39:18 +0000335 if (! is_array($data))
Derek Jones269b9422008-01-28 21:00:20 +0000336 {
337 $data = array('name' => $data);
338 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000339
Derek Jones269b9422008-01-28 21:00:20 +0000340 $data['type'] = 'radio';
341 return form_checkbox($data, $value, $checked, $extra);
342 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000343}
344
345// ------------------------------------------------------------------------
346
347/**
348 * Submit Button
349 *
350 * @access public
351 * @param mixed
352 * @param string
353 * @param string
354 * @return string
Derek Jones269b9422008-01-28 21:00:20 +0000355 */
356if (! function_exists('form_submit'))
357{
358 function form_submit($data = '', $value = '', $extra = '')
359 {
Derek Allard73274992008-05-05 16:39:18 +0000360 $defaults = array('type' => 'submit', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value);
Derek Allardf3e8a352008-01-04 14:30:38 +0000361
Derek Jones269b9422008-01-28 21:00:20 +0000362 return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
363 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000364}
365
366// ------------------------------------------------------------------------
367
368/**
369 * Reset Button
370 *
371 * @access public
372 * @param mixed
373 * @param string
374 * @param string
375 * @return string
376 */
Derek Jones269b9422008-01-28 21:00:20 +0000377if (! function_exists('form_reset'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000378{
Derek Jones269b9422008-01-28 21:00:20 +0000379 function form_reset($data = '', $value = '', $extra = '')
380 {
Derek Allard73274992008-05-05 16:39:18 +0000381 $defaults = array('type' => 'reset', 'name' => ((! is_array($data)) ? $data : ''), 'value' => $value);
Derek Allardf3e8a352008-01-04 14:30:38 +0000382
Derek Jones269b9422008-01-28 21:00:20 +0000383 return "<input ".parse_form_attributes($data, $defaults).$extra." />\n";
384 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000385}
386
387// ------------------------------------------------------------------------
388
389/**
Derek Allard707d0e02008-03-18 11:50:00 +0000390 * Form Button
391 *
392 * @access public
393 * @param mixed
394 * @param string
395 * @param string
396 * @return string
397 */
398if (! function_exists('form_button'))
399{
400 function form_button($data = '', $content = '', $extra = '')
401 {
Derek Allard73274992008-05-05 16:39:18 +0000402 $defaults = array('name' => ((! is_array($data)) ? $data : ''), 'type' => 'submit');
Derek Allard707d0e02008-03-18 11:50:00 +0000403
404 if ( is_array($data) AND isset($data['content']))
405 {
406 $content = $data['content'];
407 unset($data['content']); // content is not an attribute
408 }
409
410 return "<button ".parse_form_attributes($data, $defaults).$extra.">".$content."</button>\n";
411 }
412}
413
414// ------------------------------------------------------------------------
415
416/**
Derek Allardf3e8a352008-01-04 14:30:38 +0000417 * Form Label Tag
418 *
419 * @access public
420 * @param string The text to appear onscreen
421 * @param string The id the label applies to
422 * @param string Additional attributes
423 * @return string
424 */
Derek Jones269b9422008-01-28 21:00:20 +0000425if (! function_exists('form_label'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000426{
Derek Jones269b9422008-01-28 21:00:20 +0000427 function form_label($label_text = '', $id = '', $attributes = array())
428 {
Derek Allardf3e8a352008-01-04 14:30:38 +0000429
Derek Jones269b9422008-01-28 21:00:20 +0000430 $label = '<label';
Derek Allardf3e8a352008-01-04 14:30:38 +0000431
Derek Jones269b9422008-01-28 21:00:20 +0000432 if ($id != '')
Derek Allardf3e8a352008-01-04 14:30:38 +0000433 {
Derek Jones269b9422008-01-28 21:00:20 +0000434 $label .= " for=\"$id\"";
Derek Allardf3e8a352008-01-04 14:30:38 +0000435 }
Derek Jones269b9422008-01-28 21:00:20 +0000436
437 if (is_array($attributes) AND count($attributes) > 0)
438 {
439 foreach ($attributes as $key => $val)
440 {
441 $label .= ' '.$key.'="'.$val.'"';
442 }
443 }
444
445 $label .= ">$label_text</label>";
446
447 return $label;
Derek Allardf3e8a352008-01-04 14:30:38 +0000448 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000449}
450
451// ------------------------------------------------------------------------
452/**
453 * Fieldset Tag
454 *
455 * Used to produce <fieldset><legend>text</legend>. To close fieldset
456 * use form_fieldset_close()
457 *
458 * @access public
459 * @param string The legend text
460 * @param string Additional attributes
461 * @return string
462 */
Derek Jones269b9422008-01-28 21:00:20 +0000463if (! function_exists('form_fieldset'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000464{
Derek Jones269b9422008-01-28 21:00:20 +0000465 function form_fieldset($legend_text = '', $attributes = array())
Derek Allardf3e8a352008-01-04 14:30:38 +0000466 {
Derek Jones269b9422008-01-28 21:00:20 +0000467
468 $fieldset = "<fieldset";
469
470 if (is_array($attributes) AND count($attributes) > 0)
Derek Allardf3e8a352008-01-04 14:30:38 +0000471 {
Derek Jones269b9422008-01-28 21:00:20 +0000472 foreach ($attributes as $key => $val)
473 {
474 $fieldset .= ' '.$key.'="'.$val.'"';
475 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000476 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000477
Derek Jones269b9422008-01-28 21:00:20 +0000478 $fieldset .= ">\n";
Derek Allardf3e8a352008-01-04 14:30:38 +0000479
Derek Jones269b9422008-01-28 21:00:20 +0000480 if ($legend_text != '')
481 {
482 $fieldset .= "<legend>$legend_text</legend>\n";
483 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000484
485
486
Derek Jones269b9422008-01-28 21:00:20 +0000487 return $fieldset;
488 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000489}
490
491// ------------------------------------------------------------------------
492
493/**
494 * Fieldset Close Tag
495 *
496 * @access public
497 * @param string
498 * @return string
499 */
Derek Jones269b9422008-01-28 21:00:20 +0000500if (! function_exists('form_fieldset_close'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000501{
Derek Jones269b9422008-01-28 21:00:20 +0000502 function form_fieldset_close($extra = '')
503 {
504 return "</fieldset>\n".$extra;
505 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000506}
507
508// ------------------------------------------------------------------------
509
510/**
511 * Form Close Tag
512 *
513 * @access public
514 * @param string
515 * @return string
516 */
Derek Jones269b9422008-01-28 21:00:20 +0000517if (! function_exists('form_close'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000518{
Derek Jones269b9422008-01-28 21:00:20 +0000519 function form_close($extra = '')
520 {
521 return "</form>\n".$extra;
522 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000523}
524
525// ------------------------------------------------------------------------
526
527/**
528 * Form Prep
529 *
530 * Formats text so that it can be safely placed in a form field in the event it has HTML tags.
531 *
532 * @access public
533 * @param string
534 * @return string
535 */
Derek Jones269b9422008-01-28 21:00:20 +0000536if (! function_exists('form_prep'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000537{
Derek Jones269b9422008-01-28 21:00:20 +0000538 function form_prep($str = '')
Derek Allardf3e8a352008-01-04 14:30:38 +0000539 {
Derek Jones269b9422008-01-28 21:00:20 +0000540 if ($str === '')
541 {
542 return '';
543 }
544
545 $temp = '__TEMP_AMPERSANDS__';
546
547 // Replace entities to temporary markers so that
548 // htmlspecialchars won't mess them up
549 $str = preg_replace("/&#(\d+);/", "$temp\\1;", $str);
550 $str = preg_replace("/&(\w+);/", "$temp\\1;", $str);
551
552 $str = htmlspecialchars($str);
553
554 // In case htmlspecialchars misses these.
555 $str = str_replace(array("'", '"'), array("&#39;", "&quot;"), $str);
556
557 // Decode the temp markers back to entities
558 $str = preg_replace("/$temp(\d+);/","&#\\1;",$str);
559 $str = preg_replace("/$temp(\w+);/","&\\1;",$str);
560
561 return $str;
Derek Allardf3e8a352008-01-04 14:30:38 +0000562 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000563}
564
565// ------------------------------------------------------------------------
566
567/**
568 * Parse the form attributes
569 *
570 * Helper function used by some of the form helpers
571 *
572 * @access private
573 * @param array
574 * @param array
575 * @return string
576 */
Derek Jones269b9422008-01-28 21:00:20 +0000577if (! function_exists('parse_form_attributes'))
Derek Allardf3e8a352008-01-04 14:30:38 +0000578{
Derek Jones269b9422008-01-28 21:00:20 +0000579 function parse_form_attributes($attributes, $default)
Derek Allardf3e8a352008-01-04 14:30:38 +0000580 {
Derek Jones269b9422008-01-28 21:00:20 +0000581 if (is_array($attributes))
Derek Allardf3e8a352008-01-04 14:30:38 +0000582 {
Derek Jones269b9422008-01-28 21:00:20 +0000583 foreach ($default as $key => $val)
Derek Allardf3e8a352008-01-04 14:30:38 +0000584 {
Derek Jones269b9422008-01-28 21:00:20 +0000585 if (isset($attributes[$key]))
586 {
587 $default[$key] = $attributes[$key];
588 unset($attributes[$key]);
589 }
590 }
591
592 if (count($attributes) > 0)
593 {
594 $default = array_merge($default, $attributes);
Derek Allardf3e8a352008-01-04 14:30:38 +0000595 }
596 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000597
Derek Jones269b9422008-01-28 21:00:20 +0000598 $att = '';
599 foreach ($default as $key => $val)
Derek Allardf3e8a352008-01-04 14:30:38 +0000600 {
Derek Jones269b9422008-01-28 21:00:20 +0000601 if ($key == 'value')
602 {
603 $val = form_prep($val);
604 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000605
Derek Jones269b9422008-01-28 21:00:20 +0000606 $att .= $key . '="' . $val . '" ';
607 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000608
Derek Jones269b9422008-01-28 21:00:20 +0000609 return $att;
610 }
Derek Allardf3e8a352008-01-04 14:30:38 +0000611}
612
Derek Jonesa3ffbbb2008-05-11 18:18:29 +0000613
614/* End of file form_helper.php */
615/* Location: ./system/helpers/form_helper.php */