Ka Extensions for OpenCart 4

This documentation applies to Ka Extensions for OpenCart 4.x only. It is not compatible with OpenCart 3.

TraitControllerForm

Helpful functions for forms: field values, errors and validation.

Table of Contents

Properties

Methods

getFieldsWithData()  : array<string|int, mixed>
Fills fields with values from old and new data and attaches errors.
getFieldValues()  : array<string|int, mixed>
Returns code => value pairs from fields.
getFieldWithData()  : array<string|int, mixed>
Fills a field with its value: from new data, then old data, then the default value. Formats prices and prepares thumbnails for image fields.
validateField()  : bool
Validates a field (required, presence, number min and max) and writes errors to $this->errors.
validateFields()  : bool
Validates all fields.

Properties

Methods

getFieldsWithData()

Fills fields with values from old and new data and attaches errors.

protected getFieldsWithData(mixed $fields, mixed $old_data[, mixed $new_data = null ][, mixed $errors = array() ]) : array<string|int, mixed>

$fields — field metadata arrays. $old_data — old data, e.g. from the database. $new_data — new data when the form was submitted, otherwise null. $errors — errors indexed by field code.

Parameters
$fields : mixed
$old_data : mixed
$new_data : mixed = null
$errors : mixed = array()
Return values
array<string|int, mixed> —

Fields with values.

getFieldValues()

Returns code => value pairs from fields.

protected getFieldValues(mixed $fields) : array<string|int, mixed>

$fields — fields with values.

Parameters
$fields : mixed
Return values
array<string|int, mixed> —

Field values.

getFieldWithData()

Fills a field with its value: from new data, then old data, then the default value. Formats prices and prepares thumbnails for image fields.

protected getFieldWithData(mixed $k, mixed $f, mixed $old_data, mixed $new_data) : array<string|int, mixed>

$k — field code. $f — field metadata array. $old_data — old data, e.g. from the database. $new_data — new data (POST array) or null.

Parameters
$k : mixed
$f : mixed
$old_data : mixed
$new_data : mixed
Return values
array<string|int, mixed> —

Field with the value.

validateField()

Validates a field (required, presence, number min and max) and writes errors to $this->errors.

protected validateField(mixed $code, mixed $field, mixed $post) : bool

$code — field code. $field — field metadata. $post — submitted data.

Parameters
$code : mixed
$field : mixed
$post : mixed
Return values
bool —

False if the field is required but empty or missing. Min and max errors are recorded but still return true.

validateFields()

Validates all fields.

protected validateFields(mixed $fields, mixed $post) : bool

$fields — field metadata arrays. $post — submitted data.

Parameters
$fields : mixed
$post : mixed
Return values
bool —

True if there are no errors.


        
On this page

Search results