########### Form Helper ########### The Form Helper file contains functions that assist in working with forms. .. contents:: Page Contents Loading this Helper =================== This helper is loaded using the following code :: $this->load->helper('form'); The following functions are available: form_open() =========== Creates an opening form tag with a base URL **built from your config preferences**. It will optionally let you add form attributes and hidden input fields, and will always add the attribute accept-charset based on the charset value in your config file. The main benefit of using this tag rather than hard coding your own HTML is that it permits your site to be more portable in the event your URLs ever change. Here's a simple example :: echo form_open('email/send'); The above example would create a form that points to your base URL plus the "email/send" URI segments, like this ::
Adding Attributes ^^^^^^^^^^^^^^^^^ Attributes can be added by passing an associative array to the second parameter, like this :: $attributes = array('class' => 'email', 'id' => 'myform'); echo form_open('email/send', $attributes); The above example would create a form similar to this :: Adding Hidden Input Fields ^^^^^^^^^^^^^^^^^^^^^^^^^^ Hidden fields can be added by passing an associative array to the third parameter, like this :: $hidden = array('username' => 'Joe', 'member_id' => '234'); echo form_open('email/send', '', $hidden); The above example would create a form similar to this :: tag. The only advantage to using this function is it permits you to pass data to it which will be added below the tag. For example :: $string = ""; echo form_close($string); // Would produce: form_prep() =========== Allows you to safely use HTML and characters such as quotes within form elements without breaking out of the form. Consider this example :: $string = 'Here is a string containing "quoted" text.'; Since the above string contains a set of quotes it will cause the form to break. The `form_prep()` function converts HTML so that it can be used safely :: .. note:: If you use any of the form helper functions listed in this page the form values will be prepped automatically, so there is no need to call this function. Use it only if you are creating your own form elements. set_value() =========== 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. The second (optional) parameter allows you to set a default value for the form. Example :: The above form will show "0" when loaded for the first time. set_select() ============ If you use a