Subversion-Projekte lars-tiefland.codeigniter

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
<head>
4
 
5
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
<title>Form Helper : CodeIgniter User Guide</title>
7
 
8
<style type='text/css' media='all'>@import url('../userguide.css');</style>
9
<link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
10
 
11
<script type="text/javascript" src="../nav/nav.js"></script>
12
<script type="text/javascript" src="../nav/prototype.lite.js"></script>
13
<script type="text/javascript" src="../nav/moo.fx.js"></script>
14
<script type="text/javascript" src="../nav/user_guide_menu.js"></script>
15
 
16
<meta http-equiv='expires' content='-1' />
17
<meta http-equiv= 'pragma' content='no-cache' />
18
<meta name='robots' content='all' />
19
<meta name='author' content='ExpressionEngine Dev Team' />
20
<meta name='description' content='CodeIgniter User Guide' />
21
 
22
</head>
23
<body>
24
 
25
<!-- START NAVIGATION -->
26
<div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
27
<div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
28
<div id="masthead">
29
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
30
<tr>
31
<td><h1>CodeIgniter User Guide Version 1.7.1</h1></td>
32
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
33
</tr>
34
</table>
35
</div>
36
<!-- END NAVIGATION -->
37
 
38
 
39
<!-- START BREADCRUMB -->
40
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
41
<tr>
42
<td id="breadcrumb">
43
<a href="http://codeigniter.com/">CodeIgniter Home</a> &nbsp;&#8250;&nbsp;
44
<a href="../index.html">User Guide Home</a> &nbsp;&#8250;&nbsp;
45
Form Helper
46
</td>
47
<td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.com/user_guide/" />Search User Guide&nbsp; <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />&nbsp;<input type="submit" class="submit" name="sa" value="Go" /></form></td>
48
</tr>
49
</table>
50
<!-- END BREADCRUMB -->
51
 
52
<br clear="all" />
53
 
54
 
55
<!-- START CONTENT -->
56
<div id="content">
57
 
58
 
59
<h1>Form Helper</h1>
60
 
61
<p>The Form Helper file contains functions that assist in working with forms.</p>
62
 
63
 
64
<h2>Loading this Helper</h2>
65
 
66
<p>This helper is loaded using the following code:</p>
67
<code>$this->load->helper('form');</code>
68
 
69
<p>The following functions are available:</p>
70
 
71
 
72
 
73
<h2>form_open()</h2>
74
 
75
<p>Creates an opening form tag with a base URL <strong>built from your config preferences</strong>.  It will optionally let you
76
add form attributes and hidden input fields.</p>
77
 
78
<p>The main benefit of using this tag rather than hard coding your own HTML is that it permits your site to be more portable
79
in the event your URLs ever change.</p>
80
 
81
<p>Here's a simple example:</p>
82
 
83
<code>echo form_open('email/send');</code>
84
 
85
<p>The above example would create a form that points to your base URL plus the "email/send" URI segments, like this:</p>
86
 
87
<code>&lt;form method="post" action="http:/example.com/index.php/email/send" /></code>
88
 
89
<h4>Adding Attributes</h4>
90
 
91
<p>Attributes can be added by passing an associative array to the second parameter, like this:</p>
92
 
93
<code>
94
$attributes = array('class' => 'email', 'id' => 'myform');<br />
95
<br />
96
echo form_open('email/send', $attributes);</code>
97
 
98
<p>The above example would create a form similar to this:</p>
99
 
100
<code>&lt;form method="post" action="http:/example.com/index.php/email/send" &nbsp;class="email" &nbsp;id="myform" /></code>
101
 
102
<h4>Adding Hidden Input Fields</h4>
103
 
104
<p>Hidden fields can be added by passing an associative array to the third parameter, like this:</p>
105
 
106
<code>
107
$hidden = array('username' => 'Joe', 'member_id' => '234');<br />
108
<br />
109
echo form_open('email/send', '', $hidden);</code>
110
 
111
<p>The above example would create a form similar to this:</p>
112
 
113
<code>&lt;form method="post" action="http:/example.com/index.php/email/send"><br />
114
&lt;input type="hidden" name="username" value="Joe" /><br />
115
&lt;input type="hidden" name="member_id" value="234" /></code>
116
 
117
 
118
<h2>form_open_multipart()</h2>
119
 
120
<p>This function is absolutely identical to the <dfn>form_open()</dfn> tag above except that it adds a multipart attribute,
121
which is necessary if you would like to use the form to upload files with.</p>
122
 
123
<h2>form_hidden()</h2>
124
 
125
<p>Lets you generate hidden input fields.  You can either submit a name/value string to create one field:</p>
126
 
127
<code>form_hidden('username', 'johndoe');<br />
128
<br />
129
// Would produce:<br /><br />
130
&lt;input type="hidden" name="username" value="johndoe" /></code>
131
 
132
<p>Or you can submit an associative array to create multiple fields:</p>
133
 
134
<code>$data = array(<br />
135
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name'&nbsp;&nbsp;=> 'John Doe',<br />
136
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'email' => 'john@example.com',<br />
137
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'url'&nbsp;&nbsp;&nbsp;=> 'http://example.com'<br />
138
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
139
<br />
140
echo form_hidden($data);<br />
141
<br />
142
// Would produce:<br /><br />
143
&lt;input type="hidden" name="name" value="John Doe" /><br />
144
&lt;input type="hidden" name="email" value="john@example.com" /><br />
145
&lt;input type="hidden" name="url" value="http://example.com" /></code>
146
 
147
 
148
 
149
 
150
<h2>form_input()</h2>
151
 
152
<p>Lets you generate a standard text input field.  You can minimally pass the field name and value in the first
153
and second parameter:</p>
154
 
155
<code>echo form_input('username', 'johndoe');</code>
156
 
157
<p>Or you can pass an associative array containing any data you wish your form to contain:</p>
158
 
159
<code>$data = array(<br />
160
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'name'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'username',<br />
161
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'id'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'username',<br />
162
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'value'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'johndoe',<br />
163
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'maxlength'&nbsp;&nbsp;&nbsp;=> '100',<br />
164
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'size'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> '50',<br />
165
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'style'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; => 'width:50%',<br />
166
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
167
<br />
168
echo form_input($data);<br />
169
<br />
170
// Would produce:<br /><br />
171
&lt;input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" /></code>
172
 
173
<p>If you would like your form to contain some additional data, like Javascript, you can pass it as a string in the
174
third parameter:</p>
175
 
176
<code>$js = 'onClick="some_function()"';<br />
177
<br />
178
echo form_input('username', 'johndoe', $js);</code>
179
 
180
<h2>form_password()</h2>
181
 
182
<p>This function is identical in all respects to the <dfn>form_input()</dfn> function above
183
except that is sets it as a "password" type.</p>
184
 
185
<h2>form_upload()</h2>
186
 
187
<p>This function is identical in all respects to the <dfn>form_input()</dfn> function above
188
except that is sets it as a "file" type, allowing it to be used to upload files.</p>
189
 
190
<h2>form_textarea()</h2>
191
 
192
<p>This function is identical in all respects to the <dfn>form_input()</dfn> function above
193
except that it generates a "textarea" type. Note: Instead of the "maxlength" and "size" attributes in the above
194
example, you will instead specify "rows" and "cols".</p>
195
 
196
 
197
<h2>form_dropdown()</h2>
198
 
199
<p>Lets you create a standard drop-down field.  The first parameter will contain the name of the field,
200
the second parameter will contain an associative array of options, and the third parameter will contain the
201
value you wish to be selected.  You can also pass an array through the third parameter, and CodeIgniter will create a multiple select for you. Example:</p>
202
 
203
<code>$options = array(<br />
204
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'small'&nbsp;&nbsp;=> 'Small Shirt',<br />
205
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'med'&nbsp;&nbsp;&nbsp;&nbsp;=> 'Medium Shirt',<br />
206
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'large'&nbsp;&nbsp; => 'Large Shirt',<br />
207
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'xlarge' => 'Extra Large Shirt',<br />
208
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;);<br />
209
<br />
210
$shirts_on_sale = array('small', 'large');<br />
211
<br />
212
echo form_dropdown('shirts', $options, 'large');<br />
213
<br />
214
// Would produce:<br />
215
<br />
216
&lt;select name=&quot;shirts&quot;&gt;<br />
217
&lt;option value=&quot;small&quot;&gt;Small Shirt&lt;/option&gt;<br />
218
&lt;option value=&quot;med&quot;&gt;Medium  Shirt&lt;/option&gt;<br />
219
&lt;option value=&quot;large&quot; selected=&quot;selected&quot;&gt;Large Shirt&lt;/option&gt;<br />
220
&lt;option value=&quot;xlarge&quot;&gt;Extra Large Shirt&lt;/option&gt;<br />
221
&lt;/select&gt;<br />
222
<br />
223
echo form_dropdown('shirts', $options, $shirts_on_sale);<br />
224
<br />
225
// Would produce:<br />
226
<br />
227
&lt;select name=&quot;shirts&quot; multiple=&quot;multiple&quot;&gt;<br />
228
&lt;option value=&quot;small&quot; selected=&quot;selected&quot;&gt;Small Shirt&lt;/option&gt;<br />
229
&lt;option value=&quot;med&quot;&gt;Medium  Shirt&lt;/option&gt;<br />
230
&lt;option value=&quot;large&quot; selected=&quot;selected&quot;&gt;Large Shirt&lt;/option&gt;<br />
231
&lt;option value=&quot;xlarge&quot;&gt;Extra Large Shirt&lt;/option&gt;<br />
232
&lt;/select&gt;</code>
233
 
234
 
235
<p>If you would like the opening &lt;select> to contain additional data, like an <kbd>id</kbd> attribute or JavaScript, you can pass it as a string in the
236
fourth parameter:</p>
237
 
238
<code>$js = 'id="shirts" onChange="some_function();"';<br />
239
<br />
240
echo form_dropdown('shirts', $options, 'large', $js);</code>
241
 
242
<p>If the array passed as $options is a multidimensional array, form_dropdown() will produce an &lt;optgroup&gt; with the array key as the label.</p>
243
 
244
<h2>form_fieldset()</h2>
245
 
246
<p>Lets you generate fieldset/legend fields.</p>
247
<code>echo form_fieldset('Address Information');<br />
248
echo &quot;&lt;p&gt;fieldset content here&lt;/p&gt;\n&quot;;<br />
249
echo form_fieldset_close();
250
<br />
251
<br />
252
// Produces<br />
253
&lt;fieldset&gt;
254
<br />
255
&lt;legend&gt;Address Information&lt;/legend&gt;
256
<br />
257
&lt;p&gt;form content here&lt;/p&gt;
258
<br />
259
&lt;/fieldset&gt;</code>
260
<p>Similar to other functions, you can submit an associative array in the second parameter if you prefer to set additional attributes. </p>
261
<p><code>$attributes = array('id' =&gt; 'address_info', 'class' =&gt; 'address_info');<br />
262
    echo form_fieldset('Address Information', $attributes);<br />
263
echo &quot;&lt;p&gt;fieldset content here&lt;/p&gt;\n&quot;;<br />
264
echo form_fieldset_close(); <br />
265
<br />
266
// Produces<br />
267
&lt;fieldset id=&quot;address_info&quot; class=&quot;address_info&quot;&gt; <br />
268
&lt;legend&gt;Address Information&lt;/legend&gt; <br />
269
&lt;p&gt;form content here&lt;/p&gt; <br />
270
&lt;/fieldset&gt;</code></p>
271
<h2>form_fieldset_close()</h2>
272
<p>Produces a closing &lt;/fieldset&gt; tag.  The only advantage to using this function is it permits you to pass data to it
273
    which will be added below the tag.  For example:</p>
274
<code>$string = &quot;&lt;/div&gt;&lt;/div&gt;&quot;;<br />
275
<br />
276
echo fieldset_close($string);<br />
277
<br />
278
// Would produce:<br />
279
&lt;/fieldset&gt;<br />
280
&lt;/div&gt;&lt;/div&gt;</code>
281
<h2>form_checkbox()</h2>
282
<p>Lets you generate a checkbox field. Simple example:</p>
283
<code>echo form_checkbox('newsletter', 'accept', TRUE);<br />
284
<br />
285
// Would produce:<br />
286
<br />
287
&lt;input type=&quot;checkbox&quot; name=&quot;newsletter&quot; value=&quot;accept&quot; checked=&quot;checked&quot; /&gt;</code>
288
<p>The third parameter contains a boolean TRUE/FALSE to determine whether the box should be checked or not.</p>
289
<p>Similar to the other form functions in this helper, you can also pass an array of attributes to the function:</p>
290
 
291
<code>$data = array(<br />
292
&nbsp;&nbsp;&nbsp;&nbsp;'name'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'newsletter',<br />
293
&nbsp;&nbsp;&nbsp;&nbsp;'id'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'newsletter',<br />
294
&nbsp;&nbsp;&nbsp;&nbsp;'value'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> 'accept',<br />
295
&nbsp;&nbsp;&nbsp;&nbsp;'checked'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=> TRUE,<br />
296
&nbsp;&nbsp;&nbsp;&nbsp;'style'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; => 'margin:10px',<br />
297
&nbsp;&nbsp;&nbsp;&nbsp;);<br />
298
<br />
299
echo form_checkbox($data);<br />
300
<br />
301
// Would produce:<br /><br />
302
&lt;input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" /></code>
303
 
304
<p>As with other functions, if you would like the tag to contain  additional data, like JavaScript, you can pass it as a string in the
305
fourth parameter:</p>
306
 
307
<code>$js = 'onClick="some_function()"';<br />
308
<br />
309
 echo form_checkbox('newsletter', 'accept', TRUE, $js)</code>
310
 
311
 
312
<h2>form_radio()</h2>
313
<p>This function is identical in all respects to the <dfn>form_checkbox()</dfn> function above except that is sets it as a "radio" type.</p>
314
 
315
 
316
<h2>form_submit()</h2>
317
 
318
<p>Lets you generate a standard submit button. Simple example:</p>
319
<code>echo form_submit('mysubmit', 'Submit Post!');<br />
320
<br />
321
// Would produce:<br />
322
<br />
323
&lt;input type=&quot;submit&quot; name=&quot;mysubmit&quot; value=&quot;Submit Post!&quot; /&gt;</code>
324
<p>Similar to other functions, you can submit an associative array in the first parameter if you prefer to set your own attributes.
325
    The third parameter lets you add extra data to your form, like JavaScript.</p>
326
<h2>form_label()</h2>
327
<p>Lets you generate a &lt;label&gt;. Simple example:</p>
328
<code>echo form_label('What is your Name', 'username');<br />
329
<br />
330
// Would produce:
331
<br />
332
&lt;label for=&quot;username&quot;&gt;What is your Name&lt;/label&gt;</code>
333
<p>Similar to other functions, you can submit an associative array in the third parameter if you prefer to set additional attributes.    </p>
334
<p><code>$attributes = array(<br />
335
&nbsp;&nbsp;&nbsp;&nbsp;'class' =&gt; 'mycustomclass',<br />
336
&nbsp;&nbsp;&nbsp;&nbsp;'style' =&gt; 'color: #000;',<br />
337
);<br />
338
    echo form_label('What is your Name', 'username', $attributes);<br />
339
        <br />
340
// Would produce: <br />
341
&lt;label for=&quot;username&quot; class=&quot;mycustomclass&quot; style=&quot;color: #000;&quot;&gt;What is your Name&lt;/label&gt;</code></p>
342
<h2>form_reset()</h2>
343
 
344
<p>Lets you generate a standard reset button. Use is identical to <dfn>form_submit()</dfn>.</p>
345
 
346
<h2>form_button()</h2>
347
 
348
<p>Lets you generate a standard button element. You can minimally pass the button name and content in the first and second parameter:</p>
349
<code>
350
echo form_button('name','content');<br />
351
<br />
352
// Would produce<br />
353
&lt;button name="name" type="button"&gt;Content&lt;/button&gt;
354
</code>
355
 
356
Or you can pass an associative array containing any data you wish your form to contain:
357
<code>
358
$data = array(<br />
359
&nbsp;&nbsp;&nbsp;&nbsp;'name' => 'button',<br />
360
&nbsp;&nbsp;&nbsp;&nbsp;'id' => 'button',<br />
361
&nbsp;&nbsp;&nbsp;&nbsp;'value' => 'true',<br />
362
&nbsp;&nbsp;&nbsp;&nbsp;'type' => 'reset',<br />
363
&nbsp;&nbsp;&nbsp;&nbsp;'content' => 'Reset'<br />
364
);<br />
365
<br />
366
echo form_button($data);<br />
367
<br />
368
// Would produce:<br />
369
&lt;button name="button" id="button" value="true" type="reset"&gt;Reset&lt;/button&gt;
370
</code>
371
 
372
If you would like your form to contain some additional data, like JavaScript, you can pass it as a string in the third parameter:
373
<code>
374
$js = 'onClick="some_function()"';<br /><br />
375
echo form_button('mybutton', 'Click Me', $js);
376
</code>
377
 
378
 
379
<h2>form_close()</h2>
380
 
381
<p>Produces a closing &lt;/form> tag.  The only advantage to using this function is it permits you to pass data to it
382
which will be added below the tag.  For example:</p>
383
 
384
<code>$string = "&lt;/div>&lt;/div>";<br />
385
<br />
386
echo form_close($string);<br />
387
<br />
388
// Would produce:<br />
389
<br />
390
&lt;/form><br />
391
&lt;/div>&lt;/div></code>
392
 
393
 
394
 
395
 
396
 
397
<h2>form_prep()</h2>
398
 
399
<p>Allows you to safely use HTML and characters such as quotes within form elements without breaking out of the form.  Consider this example:</p>
400
 
401
<code>$string = 'Here is a string containing <strong>"quoted"</strong> text.';<br />
402
<br />
403
&lt;input type="text" name="myform" value="<var>$string</var>" /></code>
404
 
405
<p>Since the above string contains a set of quotes it will cause the form to break.
406
The form_prep function converts HTML so that it can be used safely:</p>
407
 
408
<code>&lt;input type="text" name="myform" value="<var>&lt;?php echo form_prep($string); ?></var>" /></code>
409
 
410
<p class="important"><strong>Note:</strong> If you use any of the form helper functions listed in this page the form
411
values will be prepped automatically, so there is no need to call this function. Use it only if you are
412
creating your own form elements.</p>
413
 
414
 
415
<h2>set_value()</h2>
416
 
417
<p>Permits you to set the value of an input form or textarea. You must supply the field name via the first parameter of the function.
418
The second (optional) parameter allows you to set a default value for the form. Example:</p>
419
 
420
<code>&lt;input type="text" name="quantity" value="<dfn>&lt;?php echo set_value('quantity', '0'); ?></dfn>" size="50" /></code>
421
 
422
<p>The above form will show "0" when loaded for the first time.</p>
423
 
424
<h2>set_select()</h2>
425
 
426
<p>If you use a <dfn>&lt;select></dfn> menu, this function permits you to display the menu item that was selected.  The first parameter
427
must contain the name of the select menu, the second parameter must contain the value of
428
each item, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).</p>
429
 
430
<p>Example:</p>
431
 
432
<code>
433
&lt;select name="myselect"><br />
434
&lt;option value="one" <dfn>&lt;?php echo  set_select('myselect', 'one', TRUE); ?></dfn> >One&lt;/option><br />
435
&lt;option value="two" <dfn>&lt;?php echo  set_select('myselect', 'two'); ?></dfn> >Two&lt;/option><br />
436
&lt;option value="three" <dfn>&lt;?php echo  set_select('myselect', 'three'); ?></dfn> >Three&lt;/option><br />
437
&lt;/select>
438
</code>
439
 
440
 
441
<h2>set_checkbox()</h2>
442
 
443
<p>Permits you to display a checkbox in the state it was submitted.  The first parameter
444
must contain the name of the checkbox, the second parameter must contain its value, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE). Example:</p>
445
 
446
<code>&lt;input type="checkbox" name="mycheck" value="1" <dfn>&lt;?php echo set_checkbox('mycheck', '1'); ?></dfn> /><br />
447
&lt;input type="checkbox" name="mycheck" value="2" <dfn>&lt;?php echo set_checkbox('mycheck', '2'); ?></dfn> /></code>
448
 
449
 
450
<h2>set_radio()</h2>
451
 
452
<p>Permits you to display radio buttons in the state they were submitted. This function is identical to the <strong>set_checkbox()</strong> function above.</p>
453
 
454
<code>&lt;input type="radio" name="myradio" value="1" <dfn>&lt;?php echo  set_radio('myradio', '1', TRUE); ?></dfn> /><br />
455
&lt;input type="radio" name="myradio" value="2" <dfn>&lt;?php echo  set_radio('myradio', '2'); ?></dfn> /></code>
456
 
457
 
458
 
459
 
460
</div>
461
<!-- END CONTENT -->
462
 
463
 
464
<div id="footer">
465
<p>
466
Previous Topic:&nbsp;&nbsp;<a href="file_helper.html">File Helper</a>
467
&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
468
<a href="#top">Top of Page</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
469
<a href="../index.html">User Guide Home</a>&nbsp;&nbsp;&nbsp;&middot;&nbsp;&nbsp;
470
Next Topic:&nbsp;&nbsp;<a href="html_helper.html">HTML Helper</a>
471
</p>
472
<p><a href="http://codeigniter.com">CodeIgniter</a> &nbsp;&middot;&nbsp; Copyright &#169; 2006-2008 &nbsp;&middot;&nbsp; <a href="http://ellislab.com/">Ellislab, Inc.</a></p>
473
</div>
474
 
475
</body>
476
</html>