FormValidator::validateForm

Usage

bool FormValidator::validateForm(string $form_alias, [ array $attr = [] ], [ string $error_type = 'view' ])

Description

Validate any HTML Form component based off the attributes of the form field (required, data type, min / max length, etc.). Will also execute the `validate()` method within the form component class for any custom validation rules.

Parameters

Parameter Required Type Description
$form_alias Yes string The alias of the HTML form component formatted as 'PACKAGE.ALIAS'.
$attr No array Associative array containing all attributes within the function HTML tag that displays the form.
$error_type No string Can be either 'view' or 'error' and defines whether errors will be displayed as callouts on the next page or if processing should stop and an exception be thrown with error page displayed. Defaults to 'view'

Return Value

Boolean as to whether or not form validation was successful

Examples

Validate Form


function addProduct(): ?Product { // Validate form if (!$this->validator->validateForm('shop.product')) { return null; } }

See Also