class Form extends Container implements HtmlStringable

Creates, validates and renders HTML forms.

Constants

Equal

validator

IsIn

validator

NotEqual

validator

IsNotIn

validator

Filled

validator

Blank

validator

Required

validator

Valid

validator

Submitted

validator

MinLength

validator

MaxLength

validator

Length

validator

Email

validator

URL

validator

Pattern

validator

PatternInsensitive

validator

Integer

validator

Numeric

validator

Float

validator

Min

validator

Max

validator

Range

validator

Count

validator

MaxFileSize

validator

MimeType

validator

Image

validator

MaxPostSize

validator

Get

method

Post

method

DataText

submitted data types

DataLine

submitted data types

DataFile

submitted data types

DataKeys

submitted data types

internal TrackerId

internal ProtectorId

EQUAL

IS_IN

NOT_EQUAL

IS_NOT_IN

FILLED

BLANK

REQUIRED

VALID

SUBMITTED

MIN_LENGTH

MAX_LENGTH

LENGTH

EMAIL

PATTERN

PATTERN_ICASE

INTEGER

NUMERIC

FLOAT

MIN

MAX

RANGE

COUNT

MAX_FILE_SIZE

MIME_TYPE

IMAGE

MAX_POST_SIZE

GET

POST

DATA_TEXT

DATA_LINE

DATA_FILE

DATA_KEYS

TRACKER_ID

PROTECTOR_ID

Properties

$onSuccess

Occurs when the form is submitted and successfully validated

$onError
$onSubmit
$onRender
internal $httpRequest
protected bool $crossOrigin
string $action
string $method
array read-only $errors
array read-only $ownErrors
Html read-only $elementPrototype
FormRenderer read-only $renderer

Methods

__construct(string|null $name = null)

No description

Form|null
getForm(bool $throw = true)

Returns self.

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.

void
allowCrossOrigin()

Disables CSRF protection using a SameSite cookie.

addProtection(string|null $errorMessage = null)

Cross-Site Request Forgery (CSRF) form protection.

addGroup(string|object $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(Translator|null $translator)

Sets translate adapter.

Translator|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(SubmitterControl|null $by)

Sets the submittor control.

mixed
getHttpData(int|null $type = null, string|null $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|null $controls = null)

Performs the server side validation.

void
validateMaxPostSize()

No description

void
addError(string|object $message, bool $translate = true)

Adds global error message.

array
getErrors()

Returns global validation errors.

bool
hasErrors()

No description

void
cleanErrors()

No description

array
getOwnErrors()

Returns form's validation errors.

Html
getElementPrototype()

Returns form's HTML element template.

setRenderer(FormRenderer|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()

Renders form to string.

array
getToggles()

No description

static void
initialize(bool $reinit = false)

Initialize standalone forms.

Details

at line 169
__construct(string|null $name = null)

No description

Parameters

string|null $name

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

Returns self.

Parameters

bool $throw

Return Value

Form|null

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

Sets form's action.

Parameters

string|object $url

Return Value

Form

at line 211
mixed getAction()

Returns form's action.

Return Value

mixed

at line 221
Form setMethod(string $method)

Sets form's method GET or POST.

Parameters

string $method

Return Value

Form

at line 235
string getMethod()

Returns form's method.

Return Value

string

at line 244
bool isMethod(string $method)

Checks if the request method is the given one.

Parameters

string $method

Return Value

bool

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

Changes forms's HTML attribute.

Parameters

string $name
$value

Return Value

Form

at line 264
void allowCrossOrigin()

Disables CSRF protection using a SameSite cookie.

Return Value

void

at line 273
CsrfProtection addProtection(string|null $errorMessage = null)

Cross-Site Request Forgery (CSRF) form protection.

Parameters

string|null $errorMessage

Return Value

CsrfProtection

at line 287
ControlGroup addGroup(string|object $caption = null, bool $setAsCurrent = true)

Adds fieldset group to the form.

Parameters

string|object $caption
bool $setAsCurrent

Return Value

ControlGroup

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

Removes fieldset group from form.

Parameters

string|ControlGroup $name

Return Value

void

at line 332
array getGroups()

Returns all defined groups.

Return Value

array

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

Returns the specified group.

Parameters

string|int $name

Return Value

ControlGroup|null

at line 355
Form setTranslator(Translator|null $translator)

Sets translate adapter.

Parameters

Translator|null $translator

Return Value

Form

at line 365
Translator|null getTranslator()

Returns translate adapter.

Return Value

Translator|null

at line 377
bool isAnchored()

Tells if the form is anchored.

Return Value

bool

at line 387
SubmitterControl|bool isSubmitted()

Tells if the form was submitted.

Return Value

SubmitterControl|bool

submittor control

at line 400
bool isSuccess()

Tells if the form was submitted and successfully validated.

Return Value

bool

at line 411
Form setSubmittedBy(SubmitterControl|null $by)

internal  
 

Sets the submittor control.

Parameters

SubmitterControl|null $by

Return Value

Form

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

Returns submitted HTTP data.

Parameters

int|null $type
string|null $htmlName

Return Value

mixed

at line 445
void fireEvents()

Fires submit/click events.

Return Value

void

at line 510
Form reset()

Resets form.

Return Value

Form

at line 521
protected array|null receiveHttpData()

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

Return Value

array|null

at line 554
void validate(array|null $controls = null)

Performs the server side validation.

Parameters

array|null $controls

Return Value

void

at line 567
void validateMaxPostSize()

internal  
 

No description

Return Value

void

at line 584
void addError(string|object $message, bool $translate = true)

Adds global error message.

Parameters

string|object $message
bool $translate

Return Value

void

at line 597
array getErrors()

Returns global validation errors.

Return Value

array

at line 603
bool hasErrors()

No description

Return Value

bool

at line 609
void cleanErrors()

No description

Return Value

void

at line 618
array getOwnErrors()

Returns form's validation errors.

Return Value

array

at line 630
Html getElementPrototype()

Returns form's HTML element template.

Return Value

Html

at line 646
Form setRenderer(FormRenderer|null $renderer)

Sets form renderer.

Parameters

FormRenderer|null $renderer

Return Value

Form

at line 656
FormRenderer getRenderer()

Returns form renderer.

Return Value

FormRenderer

at line 666
protected beforeRender()

No description

at line 674
void fireRenderEvents()

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

Return Value

void

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

Renders form.

Parameters

...$args

Return Value

void

at line 698
string __toString()

Renders form to string.

Return Value

string

at line 715
array getToggles()

No description

Return Value

array

at line 732
static void initialize(bool $reinit = false)

Initialize standalone forms.

Parameters

bool $reinit

Return Value

void