class Form extends Container implements IHtmlString

Creates, validates and renders HTML forms.

Constants

EQUAL

validator

IS_IN

validator

NOT_EQUAL

validator

IS_NOT_IN

validator

FILLED

validator

BLANK

validator

REQUIRED

validator

VALID

validator

SUBMITTED

validator

MIN_LENGTH

validator

MAX_LENGTH

validator

LENGTH

validator

EMAIL

validator

URL

validator

PATTERN

validator

PATTERN_ICASE

validator

INTEGER

validator

NUMERIC

validator

FLOAT

validator

MIN

validator

MAX

validator

RANGE

validator

COUNT

validator

MAX_FILE_SIZE

validator

MIME_TYPE

validator

IMAGE

validator

MAX_POST_SIZE

validator

GET

method

POST

method

DATA_TEXT

submitted data types

DATA_LINE

submitted data types

DATA_FILE

submitted data types

DATA_KEYS

submitted data types

TRACKER_ID

PROTECTOR_ID

Properties

callable[]&(callable(Form, $onSuccess
callable[]&(callable(Form): $onError
callable[]&(callable(Form): $onSubmit
callable[]&(callable(Form): $onRender
$httpRequest
string $action
string $method

Methods

__construct(string $name = null)

Form constructor.

Form|null
getForm(bool $throw = true)

Returns form.

setAction(string|object $url)

Sets form's action.

mixed
getAction()

Returns form's action.

setMethod(string $method)

Sets form's method GET or POST.

string
getMethod()

Returns form's method.

bool
isMethod(string $method)

Checks if the request method is the given one.

setHtmlAttribute(string $name, $value = true)

Changes forms's HTML attribute.

addProtection(string $errorMessage = null)

Cross-Site Request Forgery (CSRF) form protection.

addGroup(string $caption = null, bool $setAsCurrent = true)

Adds fieldset group to the form.

void
removeGroup(string|ControlGroup $name)

Removes fieldset group from form.

array
getGroups()

Returns all defined groups.

ControlGroup|null
getGroup(string|int $name)

Returns the specified group.

setTranslator(ITranslator|null $translator)

Sets translate adapter.

ITranslator|null
getTranslator()

Returns translate adapter.

bool
isAnchored()

Tells if the form is anchored.

isSubmitted()

Tells if the form was submitted.

bool
isSuccess()

Tells if the form was submitted and successfully validated.

setSubmittedBy(ISubmitterControl|null $by)

Sets the submittor control.

mixed
getHttpData(int $type = null, string $htmlName = null)

Returns submitted HTTP data.

void
fireEvents()

Fires submit/click events.

reset()

Resets form.

array|null
receiveHttpData()

Internal: returns submitted HTTP data or null when form was not submitted.

void
validate(array $controls = null)

Performs the server side validation.

void
validateMaxPostSize()

No description

void
addError($message, bool $translate = true)

Adds global error message.

array
getErrors()

Returns all validation errors.

bool
hasErrors()

No description

void
cleanErrors()

No description

array
getOwnErrors()

Returns form's validation errors.

getElementPrototype()

Returns form's HTML element template.

setRenderer(IFormRenderer|null $renderer)

Sets form renderer.

getRenderer()

Returns form renderer.

beforeRender()

No description

void
fireRenderEvents()

Must be called before form is rendered and render() is not used.

void
render(...$args)

Renders form.

string
__toString()

Returns string in HTML format

array
getToggles()

No description

Details

at line 127
__construct(string $name = null)

Form constructor.

Parameters

string $name

at line 146
Form|null getForm(bool $throw = true)

Returns form.

Parameters

bool $throw

Return Value

Form|null

at line 157
Form setAction(string|object $url)

Sets form's action.

Parameters

string|object $url

Return Value

Form

at line 168
mixed getAction()

Returns form's action.

Return Value

mixed

at line 178
Form setMethod(string $method)

Sets form's method GET or POST.

Parameters

string $method

Return Value

Form

at line 191
string getMethod()

Returns form's method.

Return Value

string

at line 200
bool isMethod(string $method)

Checks if the request method is the given one.

Parameters

string $method

Return Value

bool

at line 210
Form setHtmlAttribute(string $name, $value = true)

Changes forms's HTML attribute.

Parameters

string $name
$value

Return Value

Form

at line 220
CsrfProtection addProtection(string $errorMessage = null)

Cross-Site Request Forgery (CSRF) form protection.

Parameters

string $errorMessage

Return Value

CsrfProtection

at line 231
ControlGroup addGroup(string $caption = null, bool $setAsCurrent = true)

Adds fieldset group to the form.

Parameters

string $caption
bool $setAsCurrent

Return Value

ControlGroup

at line 253
void removeGroup(string|ControlGroup $name)

Removes fieldset group from form.

Parameters

string|ControlGroup $name

Return Value

void

at line 278
array getGroups()

Returns all defined groups.

Return Value

array

at line 288
ControlGroup|null getGroup(string|int $name)

Returns the specified group.

Parameters

string|int $name

Return Value

ControlGroup|null

at line 301
Form setTranslator(ITranslator|null $translator)

Sets translate adapter.

Parameters

ITranslator|null $translator

Return Value

Form

at line 311
ITranslator|null getTranslator()

Returns translate adapter.

Return Value

ITranslator|null

at line 323
bool isAnchored()

Tells if the form is anchored.

Return Value

bool

at line 333
ISubmitterControl|bool isSubmitted()

Tells if the form was submitted.

Return Value

ISubmitterControl|bool submittor control

at line 345
bool isSuccess()

Tells if the form was submitted and successfully validated.

Return Value

bool

at line 356
Form setSubmittedBy(ISubmitterControl|null $by)

Sets the submittor control.

Parameters

ISubmitterControl|null $by

Return Value

Form

at line 367
mixed getHttpData(int $type = null, string $htmlName = null)

Returns submitted HTTP data.

Parameters

int $type
string $htmlName

Return Value

mixed

at line 387
void fireEvents()

Fires submit/click events.

Return Value

void

at line 445
Form reset()

Resets form.

Return Value

Form

at line 456
protected array|null receiveHttpData()

Internal: returns submitted HTTP data or null when form was not submitted.

Return Value

array|null

at line 485
void validate(array $controls = null)

Performs the server side validation.

Parameters

array $controls

Return Value

void

at line 497
void validateMaxPostSize()

Return Value

void

at line 513
void addError($message, bool $translate = true)

Adds global error message.

Parameters

$message
bool $translate

Return Value

void

at line 525
array getErrors()

Returns all validation errors.

Return Value

array

at line 531
bool hasErrors()

Return Value

bool

at line 537
void cleanErrors()

Return Value

void

at line 546
array getOwnErrors()

Returns form's validation errors.

Return Value

array

at line 558
Html getElementPrototype()

Returns form's HTML element template.

Return Value

Html

at line 573
Form setRenderer(IFormRenderer|null $renderer)

Sets form renderer.

Parameters

IFormRenderer|null $renderer

Return Value

Form

at line 583
IFormRenderer getRenderer()

Returns form renderer.

Return Value

IFormRenderer

at line 592
protected beforeRender()

at line 600
void fireRenderEvents()

Must be called before form is rendered and render() is not used.

Return Value

void

at line 613
void render(...$args)

Renders form.

Parameters

...$args

Return Value

void

at line 624
string __toString()

Returns string in HTML format

Return Value

string

at line 653
array getToggles()

Return Value

array