\apex\app\utilsforms

HTML Forms Library

Service: apex\services\utils\forms

Handles various form functionality such as easy server-side validation of form components, obtaining an uploaded file, the value of a checkbox, date interval, etc.

This class is available within the services container, meaning its methods can be accessed statically via the service singleton as shown below.

PHP Example

</php

namespace apex;

use apex\app; use apex\services\utils\forms;

// Validate the users:register form forms::validate_form('users:register');

Summary

Methods
Properties
Constants
validate_fields()
validate_form()
get_uploaded_file()
get_chk()
get_date_interval()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

validate_fields()

validate_fields(string  $error_type = 'template', array  $required = array(), array  $datatypes = array(), array  $minlength = array(), array  $maxlength = array(), array  $labels = array()) 

Validate form fields

Validates form fields as needed. Can either pass any errors to the template engine, or trigger an error displaying the error template. if $error_type is 'template', you can check if errors occured via the template:has_errors property.

Parameters

string $error_type

Must be either 'template' or 'error'.

array $required

One dimensional array containg names of form fields that are required, and can not be left blank.

array $datatypes

Associate array specifying which form fields should match which type.

array $minlength

Associate array for any form fields that have a minimum required length.

array $maxlength

Associate array for any form fields that have a maximum required length.

array $labels

Optionaly specify labels for form fields to use within error messages. Defaults to ucwords() version of field name.

validate_form()

validate_form(string  $form_alias, string  $error_type = 'template', array  $data = array()) 

Validates a Apex supported 'form' component, using the $form_fields array provided by the component.

Parameters

string $form_alias

Standard formatted Apex compoent alias of PACKAGE:ALIAS

string $error_type

Must be either 'template' or 'error'.

array $data

Optional array that will be passed to the validate() method of the form component for additional validation.

get_uploaded_file()

get_uploaded_file(string  $var) 

Gets the contents, filename and mime type of an uploaded file.

Parameters

string $var

The form field name of the uploaded file.

get_chk()

get_chk(string  $var) 

Get checkbox values

Get values of a checkbox form field. Does not give undefined errors if no checkboxes are ticked, and ensures always an array is returned instead of a scalar.

Parameters

string $var

The form field name of the checkbox field.

get_date_interval()

get_date_interval(string  $name) 

Get date interval

Returns the value of the tag, which consits of two form fields, the period (days, weeks, months, years), and the length.

Parameters

string $name

The name of the form field used within the tag.