tml_add_form_field()

Add a field to a TML form.

Description

Theme_My_Login_Form_Field tml_add_form_field( mixed $form, mixed $field [, array $args ] )

Add a new field to an existing TML form.

Parameters

form

The form to add the field to. May be either a string or a Theme_My_Login_Form object.

field

The field to add to the form. May be either string or a Theme_My_Login_Form_Field object.

args

An array of arguments for adding a form field. This parameter is only used if field is a string. Acceptable arguments are as follows:

  • string type
    The field type. May be one of the following: 'text', 'textarea', 'checkbox', 'radio-group', 'dropdown', 'hidden' or 'custom'. Default is 'text'.
  • string value
    The field value. This is also used as the selected value if type is set to 'dropdown' or 'radio-group'. Default is empty.
  • string label
    The field label text. If empty, no label will be shown. Default is empty.
  • string description
    The field description. This is shown below the field. Default is empty.
  • string error
    The field error message. This is shown below the field. Default is empty.
  • string content
    The field content. Used if type is set to 'custom'. Default is empty.
  • array options
    The field options. Used if type is set to 'dropdown' or 'radio-group'. Default is empty.
  • array attributes
    The field attributes. Default is empty.
  • string class
    The field class. Default is empty.
  • int priority
    The priority of the field. This affects the order of the field within the form. Default is empty.
  • array render_args
    Arguments used for rendering the field. Acceptable arguments are as follows:
    • string before
      Content to be rendered before the field. The placeholder %s can be used for the field name. Default '<div class="tml-field-wrap tml-%s-wrap">' unless type is 'hidden', then it is empty.
    • string after
      Content to be rendered after the field. Default is '</div>' unless type is 'hidden', then it is empty.
    • string control_before
      Content to be rendered before the field control. Default is empty.
    • string control_after
      Content to be rendered after the field control. Default is empty.

Return Values

The Theme_My_Login_Form_Field object is returned.

Examples

Example #1 Adding a form field using an array

tml_add_form_field( 'register', 'first_name', array(
	'type' => 'text',
	'value' => tml_get_request_value( 'first_name', 'post' ),
	'label' => 'First Name',
	'description' => 'Enter your first name.',
	'priority' => 5,
) );

Example #2 Adding a custom form field

tml_add_form_field( 'register', 'custom', array(
	'type' => 'custom',
	'content' => 'The content of my custom form field.',
	'priority' => 5,
) );