===== Form Helpers ===== Form Helpers are Akelos functions designed to make the code that produces web forms more streamlined and easier to read. Sometimes a Helper will be used instead of an HTML/PHP statement. At other times, a Helper will be a single statement that would require a number of HTML/PHP statements to write without it. A form built without Akelos Form Helpers might look like:
Name: Password: Single?: Description:
The following is an example of the same form built with Akelos Stand Alone Form Helpers. The $person object was assigned by an action on the controller:
Name: text_field("person", "name", array("size" => 20)) ?> Password: password_field("person", "password", array("maxsize" => 20)) ?> Single?: check_box("person", "single") ?> Description: text_area("person", "description", array("cols" => 20)) ?>
Here are other features that you can put into Helpers: Object name followed by square brackets creates a reference to the object's id field. Without a Helper, you'd have to write You may write the same code with this Helper:textfield("person[]", "name") ?> If the Helper is being used to generate a repetitive sequence of similar form elements, the "index" option may be used. Without the Helper, you'd have to write render_collection_of_partials needs to be referenced or documented here. This Helper, used in conjunction with the Helper render_collection_of_partials would look liketext_field("person", "name", "index" => 1) ?> ===== Form Tag Helpers ===== In this section, we will look at the functions normally used to build a form. There are three ways to write forms code. A form may use any of them, or a combination of them: - **No helper** When creating a form, it is possible to write the HTML/PHP code without any Akelos Form Helpers. Those who have programmed PHP without Akelos will be familiar with these. We showed a form written this way in the first example. - **Stand Alone Helper** The reason for the Akelos Stand Alone Helper designation is that this type does not reference the form declaration. Reference to a controller object is made from each Helper of this type. They may be used with a non-Akelos form declaration or with a Helper form declaration. If used with a Helper form declaration, the object they refer to may be different from that which is referred to by the form declaration. - **Form Tag Helper** This designation is given because this type must be coded between the form_for and end_form_tag functions. Following is a reference to the form tools. More can be seen about the HTML code at [[http://www.w3schools.com/html/html_forms.asp|w3schools]] and other HTML web sites. ^ HTML ^ Helper ^ Comment ^ | form | [[helper form|form_for]] | Wrapper for form fields; defines form | | | [[helper fields|fields_for]] | Wrapper for form fields; does not define form | | input type="text" | [[helper textfield|text_field]] | | | input type="file" | [[helper filefield|file_field]] | Input for a file name with a browse button | | input type="hidden" | [[helper hiddenfield|hidden_field]] | | | input type="password" | [[helper passwordfield|password_field]] | | | input type="radio" | [[helper radio|radio_button]] | | | checkbox | [[helper checkbox|check_box]] | | | textarea | [[helper textarea|text_area]] | | | select | [[helper select|select]] | |