Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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> |
Phil Sturgeon | 0e3263b | 2011-03-10 16:37:35 +0000 | [diff] [blame] | 31 | <td><h1>CodeIgniter User Guide Version 2.0.1</h1></td> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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> › |
| 44 | <a href="../index.html">User Guide Home</a> › |
| 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 <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <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 |
Derek Allard | 928158b | 2009-09-16 08:20:58 +0000 | [diff] [blame] | 76 | add form attributes and hidden input fields, and will always add the attribute <kbd>accept-charset</kbd> based on the charset value in your config file.</p> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
Derek Allard | 928158b | 2009-09-16 08:20:58 +0000 | [diff] [blame] | 87 | <code><form method="post" accept-charset="utf-8" action="http:/example.com/index.php/email/send" /></code> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
Derek Allard | 928158b | 2009-09-16 08:20:58 +0000 | [diff] [blame] | 100 | <code><form method="post" accept-charset="utf-8" action="http:/example.com/index.php/email/send" class="email" id="myform" /></code> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 | |
Derek Allard | 928158b | 2009-09-16 08:20:58 +0000 | [diff] [blame] | 113 | <code><form method="post" accept-charset="utf-8" action="http:/example.com/index.php/email/send"><br /> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 114 | <input type="hidden" name="username" value="Joe" /><br /> |
| 115 | <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 | <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 | 'name' => 'John Doe',<br /> |
| 136 | 'email' => 'john@example.com',<br /> |
| 137 | 'url' => 'http://example.com'<br /> |
| 138 | );<br /> |
| 139 | <br /> |
| 140 | echo form_hidden($data);<br /> |
| 141 | <br /> |
| 142 | // Would produce:<br /><br /> |
| 143 | <input type="hidden" name="name" value="John Doe" /><br /> |
| 144 | <input type="hidden" name="email" value="john@example.com" /><br /> |
| 145 | <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 | 'name' => 'username',<br /> |
| 161 | 'id' => 'username',<br /> |
| 162 | 'value' => 'johndoe',<br /> |
| 163 | 'maxlength' => '100',<br /> |
| 164 | 'size' => '50',<br /> |
| 165 | 'style' => 'width:50%',<br /> |
| 166 | );<br /> |
| 167 | <br /> |
| 168 | echo form_input($data);<br /> |
| 169 | <br /> |
| 170 | // Would produce:<br /><br /> |
| 171 | <input type="text" name="username" id="username" value="johndoe" maxlength="100" size="50" style="width:50%" /></code> |
| 172 | |
Derek Allard | 877ec2a | 2009-02-04 12:29:09 +0000 | [diff] [blame] | 173 | <p>If you would like your form to contain some additional data, like Javascript, you can pass it as a string in the |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 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 |
Robin Sowell | bb2e025 | 2009-04-20 20:34:57 +0000 | [diff] [blame] | 201 | value you wish to be selected. You can also pass an array of multiple items through the third parameter, and CodeIgniter will create a multiple select for you. Example:</p> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 202 | |
| 203 | <code>$options = array(<br /> |
| 204 | 'small' => 'Small Shirt',<br /> |
| 205 | 'med' => 'Medium Shirt',<br /> |
| 206 | 'large' => 'Large Shirt',<br /> |
| 207 | 'xlarge' => 'Extra Large Shirt',<br /> |
| 208 | );<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 | <select name="shirts"><br /> |
| 217 | <option value="small">Small Shirt</option><br /> |
| 218 | <option value="med">Medium Shirt</option><br /> |
| 219 | <option value="large" selected="selected">Large Shirt</option><br /> |
| 220 | <option value="xlarge">Extra Large Shirt</option><br /> |
| 221 | </select><br /> |
| 222 | <br /> |
| 223 | echo form_dropdown('shirts', $options, $shirts_on_sale);<br /> |
| 224 | <br /> |
| 225 | // Would produce:<br /> |
| 226 | <br /> |
| 227 | <select name="shirts" multiple="multiple"><br /> |
| 228 | <option value="small" selected="selected">Small Shirt</option><br /> |
| 229 | <option value="med">Medium Shirt</option><br /> |
| 230 | <option value="large" selected="selected">Large Shirt</option><br /> |
| 231 | <option value="xlarge">Extra Large Shirt</option><br /> |
| 232 | </select></code> |
| 233 | |
| 234 | |
Derek Allard | 877ec2a | 2009-02-04 12:29:09 +0000 | [diff] [blame] | 235 | <p>If you would like the opening <select> to contain additional data, like an <kbd>id</kbd> attribute or JavaScript, you can pass it as a string in the |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 236 | fourth parameter:</p> |
| 237 | |
Derek Allard | 877ec2a | 2009-02-04 12:29:09 +0000 | [diff] [blame] | 238 | <code>$js = 'id="shirts" onChange="some_function();"';<br /> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 239 | <br /> |
| 240 | echo form_dropdown('shirts', $options, 'large', $js);</code> |
| 241 | |
Derek Allard | 78a5fc9 | 2009-02-05 16:34:35 +0000 | [diff] [blame] | 242 | <p>If the array passed as $options is a multidimensional array, form_dropdown() will produce an <optgroup> with the array key as the label.</p> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 243 | |
Derek Jones | 2639929 | 2009-04-08 16:14:17 +0000 | [diff] [blame] | 244 | <h2>form_multiselect()</h2> |
| 245 | |
| 246 | <p>Lets you create a standard multiselect field. The first parameter will contain the name of the field, |
| 247 | the second parameter will contain an associative array of options, and the third parameter will contain the |
| 248 | value or values you wish to be selected. The parameter usage is identical to using <kbd>form_dropdown()</kbd> above, |
| 249 | except of course that the name of the field will need to use POST array syntax, e.g. <samp>foo[]</samp>.</p> |
| 250 | |
| 251 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 252 | <h2>form_fieldset()</h2> |
| 253 | |
| 254 | <p>Lets you generate fieldset/legend fields.</p> |
| 255 | <code>echo form_fieldset('Address Information');<br /> |
| 256 | echo "<p>fieldset content here</p>\n";<br /> |
| 257 | echo form_fieldset_close(); |
| 258 | <br /> |
| 259 | <br /> |
| 260 | // Produces<br /> |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 261 | <fieldset> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 262 | <br /> |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 263 | <legend>Address Information</legend> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 264 | <br /> |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 265 | <p>form content here</p> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 266 | <br /> |
| 267 | </fieldset></code> |
| 268 | <p>Similar to other functions, you can submit an associative array in the second parameter if you prefer to set additional attributes. </p> |
| 269 | <p><code>$attributes = array('id' => 'address_info', 'class' => 'address_info');<br /> |
| 270 | echo form_fieldset('Address Information', $attributes);<br /> |
| 271 | echo "<p>fieldset content here</p>\n";<br /> |
| 272 | echo form_fieldset_close(); <br /> |
| 273 | <br /> |
| 274 | // Produces<br /> |
| 275 | <fieldset id="address_info" class="address_info"> <br /> |
| 276 | <legend>Address Information</legend> <br /> |
| 277 | <p>form content here</p> <br /> |
| 278 | </fieldset></code></p> |
| 279 | <h2>form_fieldset_close()</h2> |
| 280 | <p>Produces a closing </fieldset> tag. The only advantage to using this function is it permits you to pass data to it |
| 281 | which will be added below the tag. For example:</p> |
| 282 | <code>$string = "</div></div>";<br /> |
| 283 | <br /> |
| 284 | echo fieldset_close($string);<br /> |
| 285 | <br /> |
| 286 | // Would produce:<br /> |
| 287 | </fieldset><br /> |
| 288 | </div></div></code> |
| 289 | <h2>form_checkbox()</h2> |
| 290 | <p>Lets you generate a checkbox field. Simple example:</p> |
| 291 | <code>echo form_checkbox('newsletter', 'accept', TRUE);<br /> |
| 292 | <br /> |
| 293 | // Would produce:<br /> |
| 294 | <br /> |
| 295 | <input type="checkbox" name="newsletter" value="accept" checked="checked" /></code> |
| 296 | <p>The third parameter contains a boolean TRUE/FALSE to determine whether the box should be checked or not.</p> |
| 297 | <p>Similar to the other form functions in this helper, you can also pass an array of attributes to the function:</p> |
| 298 | |
| 299 | <code>$data = array(<br /> |
| 300 | 'name' => 'newsletter',<br /> |
| 301 | 'id' => 'newsletter',<br /> |
| 302 | 'value' => 'accept',<br /> |
| 303 | 'checked' => TRUE,<br /> |
| 304 | 'style' => 'margin:10px',<br /> |
| 305 | );<br /> |
| 306 | <br /> |
| 307 | echo form_checkbox($data);<br /> |
| 308 | <br /> |
| 309 | // Would produce:<br /><br /> |
| 310 | <input type="checkbox" name="newsletter" id="newsletter" value="accept" checked="checked" style="margin:10px" /></code> |
| 311 | |
| 312 | <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 |
| 313 | fourth parameter:</p> |
| 314 | |
| 315 | <code>$js = 'onClick="some_function()"';<br /> |
| 316 | <br /> |
| 317 | echo form_checkbox('newsletter', 'accept', TRUE, $js)</code> |
| 318 | |
| 319 | |
| 320 | <h2>form_radio()</h2> |
| 321 | <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> |
| 322 | |
| 323 | |
| 324 | <h2>form_submit()</h2> |
| 325 | |
| 326 | <p>Lets you generate a standard submit button. Simple example:</p> |
| 327 | <code>echo form_submit('mysubmit', 'Submit Post!');<br /> |
| 328 | <br /> |
| 329 | // Would produce:<br /> |
| 330 | <br /> |
| 331 | <input type="submit" name="mysubmit" value="Submit Post!" /></code> |
| 332 | <p>Similar to other functions, you can submit an associative array in the first parameter if you prefer to set your own attributes. |
| 333 | The third parameter lets you add extra data to your form, like JavaScript.</p> |
| 334 | <h2>form_label()</h2> |
| 335 | <p>Lets you generate a <label>. Simple example:</p> |
| 336 | <code>echo form_label('What is your Name', 'username');<br /> |
| 337 | <br /> |
| 338 | // Would produce: |
| 339 | <br /> |
| 340 | <label for="username">What is your Name</label></code> |
| 341 | <p>Similar to other functions, you can submit an associative array in the third parameter if you prefer to set additional attributes. </p> |
| 342 | <p><code>$attributes = array(<br /> |
| 343 | 'class' => 'mycustomclass',<br /> |
| 344 | 'style' => 'color: #000;',<br /> |
| 345 | );<br /> |
| 346 | echo form_label('What is your Name', 'username', $attributes);<br /> |
| 347 | <br /> |
| 348 | // Would produce: <br /> |
| 349 | <label for="username" class="mycustomclass" style="color: #000;">What is your Name</label></code></p> |
| 350 | <h2>form_reset()</h2> |
| 351 | |
| 352 | <p>Lets you generate a standard reset button. Use is identical to <dfn>form_submit()</dfn>.</p> |
| 353 | |
| 354 | <h2>form_button()</h2> |
| 355 | |
| 356 | <p>Lets you generate a standard button element. You can minimally pass the button name and content in the first and second parameter:</p> |
| 357 | <code> |
| 358 | echo form_button('name','content');<br /> |
| 359 | <br /> |
| 360 | // Would produce<br /> |
Derek Allard | 904094a | 2009-02-10 14:00:34 +0000 | [diff] [blame] | 361 | <button name="name" type="button">Content</button> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 362 | </code> |
| 363 | |
| 364 | Or you can pass an associative array containing any data you wish your form to contain: |
| 365 | <code> |
| 366 | $data = array(<br /> |
| 367 | 'name' => 'button',<br /> |
| 368 | 'id' => 'button',<br /> |
| 369 | 'value' => 'true',<br /> |
| 370 | 'type' => 'reset',<br /> |
| 371 | 'content' => 'Reset'<br /> |
| 372 | );<br /> |
| 373 | <br /> |
| 374 | echo form_button($data);<br /> |
| 375 | <br /> |
| 376 | // Would produce:<br /> |
| 377 | <button name="button" id="button" value="true" type="reset">Reset</button> |
| 378 | </code> |
| 379 | |
| 380 | If you would like your form to contain some additional data, like JavaScript, you can pass it as a string in the third parameter: |
| 381 | <code> |
| 382 | $js = 'onClick="some_function()"';<br /><br /> |
| 383 | echo form_button('mybutton', 'Click Me', $js); |
| 384 | </code> |
| 385 | |
| 386 | |
| 387 | <h2>form_close()</h2> |
| 388 | |
| 389 | <p>Produces a closing </form> tag. The only advantage to using this function is it permits you to pass data to it |
| 390 | which will be added below the tag. For example:</p> |
| 391 | |
| 392 | <code>$string = "</div></div>";<br /> |
| 393 | <br /> |
| 394 | echo form_close($string);<br /> |
| 395 | <br /> |
| 396 | // Would produce:<br /> |
| 397 | <br /> |
| 398 | </form><br /> |
| 399 | </div></div></code> |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | <h2>form_prep()</h2> |
| 406 | |
| 407 | <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> |
| 408 | |
| 409 | <code>$string = 'Here is a string containing <strong>"quoted"</strong> text.';<br /> |
| 410 | <br /> |
| 411 | <input type="text" name="myform" value="<var>$string</var>" /></code> |
| 412 | |
| 413 | <p>Since the above string contains a set of quotes it will cause the form to break. |
| 414 | The form_prep function converts HTML so that it can be used safely:</p> |
| 415 | |
| 416 | <code><input type="text" name="myform" value="<var><?php echo form_prep($string); ?></var>" /></code> |
| 417 | |
| 418 | <p class="important"><strong>Note:</strong> If you use any of the form helper functions listed in this page the form |
| 419 | values will be prepped automatically, so there is no need to call this function. Use it only if you are |
| 420 | creating your own form elements.</p> |
| 421 | |
| 422 | |
| 423 | <h2>set_value()</h2> |
| 424 | |
| 425 | <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. |
| 426 | The second (optional) parameter allows you to set a default value for the form. Example:</p> |
| 427 | |
| 428 | <code><input type="text" name="quantity" value="<dfn><?php echo set_value('quantity', '0'); ?></dfn>" size="50" /></code> |
| 429 | |
| 430 | <p>The above form will show "0" when loaded for the first time.</p> |
| 431 | |
| 432 | <h2>set_select()</h2> |
| 433 | |
| 434 | <p>If you use a <dfn><select></dfn> menu, this function permits you to display the menu item that was selected. The first parameter |
| 435 | must contain the name of the select menu, the second parameter must contain the value of |
| 436 | each item, and the third (optional) parameter lets you set an item as the default (use boolean TRUE/FALSE).</p> |
| 437 | |
| 438 | <p>Example:</p> |
| 439 | |
| 440 | <code> |
| 441 | <select name="myselect"><br /> |
| 442 | <option value="one" <dfn><?php echo set_select('myselect', 'one', TRUE); ?></dfn> >One</option><br /> |
| 443 | <option value="two" <dfn><?php echo set_select('myselect', 'two'); ?></dfn> >Two</option><br /> |
| 444 | <option value="three" <dfn><?php echo set_select('myselect', 'three'); ?></dfn> >Three</option><br /> |
| 445 | </select> |
| 446 | </code> |
| 447 | |
| 448 | |
| 449 | <h2>set_checkbox()</h2> |
| 450 | |
| 451 | <p>Permits you to display a checkbox in the state it was submitted. The first parameter |
| 452 | 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> |
| 453 | |
| 454 | <code><input type="checkbox" name="mycheck" value="1" <dfn><?php echo set_checkbox('mycheck', '1'); ?></dfn> /><br /> |
| 455 | <input type="checkbox" name="mycheck" value="2" <dfn><?php echo set_checkbox('mycheck', '2'); ?></dfn> /></code> |
| 456 | |
| 457 | |
| 458 | <h2>set_radio()</h2> |
| 459 | |
| 460 | <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> |
| 461 | |
| 462 | <code><input type="radio" name="myradio" value="1" <dfn><?php echo set_radio('myradio', '1', TRUE); ?></dfn> /><br /> |
| 463 | <input type="radio" name="myradio" value="2" <dfn><?php echo set_radio('myradio', '2'); ?></dfn> /></code> |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | </div> |
| 469 | <!-- END CONTENT --> |
| 470 | |
| 471 | |
| 472 | <div id="footer"> |
| 473 | <p> |
| 474 | Previous Topic: <a href="file_helper.html">File Helper</a> |
| 475 | · |
| 476 | <a href="#top">Top of Page</a> · |
| 477 | <a href="../index.html">User Guide Home</a> · |
| 478 | Next Topic: <a href="html_helper.html">HTML Helper</a> |
| 479 | </p> |
Derek Jones | 898949f | 2011-01-28 07:42:16 -0600 | [diff] [blame] | 480 | <p><a href="http://codeigniter.com">CodeIgniter</a> · Copyright © 2006 - 2011 · <a href="http://ellislab.com/">EllisLab, Inc.</a></p> |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 481 | </div> |
| 482 | |
| 483 | </body> |
Derek Allard | 402835c | 2008-01-04 14:30:58 +0000 | [diff] [blame] | 484 | </html> |