HTML Form Component
This class only contains the one
Below describes all methods available within this class.
|field||Yes||The type of form field. The following types are supported: seperator, textbox, textarea, select, radio, checkbox, boolean, date, date_interval, amount, phone, custom, submit, button|
|value||No||The default value of the form field. Only used if another value does not take precedent, such as a record from the database or previously submitted POST data.|
|label||No||>The optional label of the form field. This is used within the left-hand side of the form table, and is what the user sees. If omitted, the uppercase version of the field name is used (eg. first_name = First name).|
|data_source||No||Only required for "select", "radio" and "checkbox" fields. Defines the data source for the options. See below for details on this value.|
|class||No||The CSS class name of the form field. Defaults to "form-control".|
|width||No||If defined, places the width within the style="width: VALUE;" attribute of the form field (eg. 80px, etc.).|
|required||Boolean (1/0), and defines whether or not the field is required.|
|datatype||The type of data that must be entered into the textbox. Can be:
minlength | Minimum length of the textbox value. maxlength | Maximum length of the textbox value. range | Number range the value must be within (eg. 5 - 20) equalto | Value must be equal to the value of the ID# of this textbox specified. If you did not directly specify an "id" attribute for the textbox, just use "#input_NAME". For example, if you have a confirm password field and you want it equal to the "password" textbox, you would use: equal = "#input_password".
textbox / textarea
The below table shows additional properties that are only available to the 'textbox' and 'textarea' fields.
|type||Can be either "text", "password" or "file". Defaults to "text".|
|placeholder||The default placeholder of the textbox.|
|onfocus||The value of the
|onblur||The value of the
|onkeyup||The value of the
The form fields "select", "radio" and "checkbox" also require a
data_source property, which defines
where to pull the list from. This
data_source attribute can be any of the below values.
||The lists defined within the
||This pulls all rows from the database table
||Pulls from a standard / system list. The
array get_record(string $record_id)
Description: Used to retrieve a record from the database or other source, to populate the form fields with values. If
<e:function> that calls the form contains a
record="..." attribute, this method is automatically called, and the values returned are used to
populate the form fields.
For example, if the .tpl template file contains the tag:
<e:function alias="display_form" alias="myblog:post" record_id="~post_id~"> ``` Then the associated .php file for the template contains: ```php template::assign('post_id', registry::get('post_id'));
~post_id~ merge field within the .tpl file will be replaced with whatever "post_id" is in the query string, and the
resultig form field will be populated with that post ID's values.
Description: This provides additional server-side form validation. Through the
forms::validate_form() call, the form
values are automatically validated against the validation properties included in the
get_fields() method, plus this method
is also called to provide any additional validation. For example, if creating a new user, this will ensure the username does not already
exist. Simply give off
template_add_message($message, 'error') calls for any validation errors that occur.
Need a Professional?
Need development work by the creator of Apex? E-mail [email protected] for a free consultation.
Subscribe to the low traffic mailing list to stay updated on Apex.