Skip to content
Mehdi Bounya edited this page Jul 14, 2018 · 6 revisions

A Form object represents the form, the fields and their options, It'll be passed to the \PHPForms\Validator() to do the validations.

Content

\PHPForms\Form() methods

construct

  • Arguments:
    • array $fields = []: An array of fields and their options, check Fields for more details.
    • array $attribs = []: An array of attributes to use for the form tag. 'attrib_name' => 'value'

addField

  • Arguments:
    • string $name: Field's name.
    • array $options: An array of options, check Fields for more details.

Add a new field to the form. If a field with the same name exists it'll be overwritten.

getField

  • Arguments:
    • string $name: Field's name
  • Returns: array|null

Return a field's options or null if none is found.

getFields

  • Returns: array|null

Return all fields or null if no fields were found.

getHTML

  • Arguments:
    • bool $beautify = true: TRUE to return formatted HTML or FALSE for a minified one
  • Returns: string

Get the form's HTML code. You don't have to use this method to build the HTML code and you will probably use your own as this method is not highly customisable and may not suit your needs.

Fields options

The fields array you will be passing should look like this:

array(
    'field_name' => [
        'option' => 'value'
     ],
);

The field_name is the input's name.

Available options are:

label:

The label is used in error messages and as a placeholder when creating the form's HTML.

type:

Valid options are the same as the ones for the type attribute, to create a text box use the textarea value.

rules:

These are the rules used to validate the submitted data, rules are separated by a pipe | (e.g. rule1|rule2). If no rules were set the data is considered valid.

If you want the Validator to not include a field in the Valid data use the ignore rule.

Read more about built-in rules

attribs:

Input's attributes, used when creating the form's HTML. The value is an array of 'attribute' => 'value'.

Clone this wiki locally