Skip to content

Adding form fields

OneBadNinja edited this page Nov 25, 2017 · 3 revisions

add_field() method

To create a form field, the add_field() method must be called on the form object.

add_field() accepts the following parameters:

  • string $field_id - The field ID which will be used for the field's id and name attributes. Alphanumeric characters only.
  • string $field_type - One of the valid field types.
  • string $label (optional) - The field label to display. Defaults to an empty string.
  • array $params (optional) - An array of optional parameters. Defaults to an empty array.
$form->add_field("first_name", "text", "First Name", array(
    "placeholder" => "Type your name here"
));

Available Field Types

HandyMail currently supports the following form field types: text, email, date, select, textarea, radio, checkbox, password

Optional Field Parameters

The following optional field parameters are parsed by handymail when supplied within $params:

  • string placeholder: The field placeholder

  • string class: An additional class selector to apply uniquely to this field (appended after any other applied classes).

  • boolean reply_to: If the field type is "email", this parameter governs whether the submitted email is added to the reply-to header. By default it is set to false.

  • string options: A required parameter for select, radio and checkbox form elements. This is where you supply the options to present to the user in string format, with each option delimited with a comma ie: "male,female".

  • int rows: This sets the rows attribute for textarea form elements. Defaults to 10.

  • int fieldset: The fieldset group number the field belongs to. You can read more about this on the Configuring Stylesheets page

Clone this wiki locally