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

deprecated EQUAL

deprecated IS_IN

deprecated NOT_EQUAL

deprecated IS_NOT_IN

deprecated FILLED

deprecated BLANK

deprecated REQUIRED

deprecated VALID

deprecated SUBMITTED

deprecated MIN_LENGTH

deprecated MAX_LENGTH

deprecated LENGTH

deprecated EMAIL

deprecated PATTERN

deprecated PATTERN_ICASE

deprecated INTEGER

deprecated NUMERIC

deprecated FLOAT

deprecated MIN

deprecated MAX

deprecated RANGE

deprecated COUNT

deprecated MAX_FILE_SIZE

deprecated MIME_TYPE

deprecated IMAGE

deprecated MAX_POST_SIZE

deprecated GET

deprecated POST

deprecated DATA_TEXT

deprecated DATA_LINE

deprecated DATA_FILE

deprecated DATA_KEYS

deprecated TRACKER_ID

deprecated 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
string[] read-only $errors
(string|Stringable)[] 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 form.

setAction(string|Stringable $url)

No description

string
getAction()

No description

setMethod(string $method)

No description

string
getMethod()

No description

bool
isMethod(string $method)

Checks if the request method is the given one.

setHtmlAttribute(string $name, mixed $value = true)

Sets a form-level HTML attribute.

void
allowCrossOrigin()

Disables the SameSite cookie CSRF protection, allowing cross-origin form submissions.

addProtection(string|null $errorMessage = null)

Adds a CSRF protection token field using a SameSite cookie.

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

Creates a new control group and optionally sets it as current for subsequent addXxx() calls.

void
removeGroup(ControlGroup $name)

Removes a group and all its controls from the form.

array
getGroups()

Returns all defined groups.

ControlGroup|null
getGroup(string|int $name)

Returns the specified group.

setTranslator(Translator|null $translator)

No description

Translator|null
getTranslator()

No description

bool
isAnchored()

Checks whether the form is attached to a request (always true for standalone forms).

SubmitterControl|bool
isSubmitted()

Returns the submitter control if the form was submitted, or false.

bool
isSuccess()

Tells if the form was submitted and successfully validated.

setSubmittedBy(SubmitterControl|null $by)

No description

FileUpload|null
getHttpData(int|null $type = null, string|null $htmlName = null)

Returns raw submitted HTTP data for a control, or all form data when called without arguments.

void
fireEvents()

Fires onSuccess, onError, onSubmit and onClick events based on submission and validation state.

reset()

Clears the submission state and resets all control values to defaults.

array|null
receiveHttpData()

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

void
validate(array|null $controls = null)

No description

void
validateMaxPostSize()

No description

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

Adds a form-level (not control-level) error message.

array
getErrors()

Returns all validation errors (own form errors merged with control errors).

bool
hasErrors()

No description

void
cleanErrors()

No description

array
getOwnErrors()

Returns form-level errors only, excluding control errors.

Html
getElementPrototype()

Returns form's HTML element template.

setRenderer(FormRenderer|null $renderer)

No description

getRenderer()

No description

beforeRender()

No description

void
fireRenderEvents()

Triggers beforeRender() and onRender events. Must be called before manual rendering (when not using render()).

void
render(mixed ...$args)

No description

string
__toString()

No description

array
getToggles()

Returns current visibility states of all toggle targets across all controls.

static void
initialize(bool $reinit = false)

Initializes HTTP request and SameSite CSRF cookie for standalone (non-DI) usage.

Details

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

No description

Parameters

string|null $name

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

Returns form.

Parameters

bool $throw

Return Value

Form|null

at line 247
Form setAction(string|Stringable $url)

No description

Parameters

string|Stringable $url

Return Value

Form

at line 254
string getAction()

No description

Return Value

string

at line 260
Form setMethod(string $method)

No description

Parameters

string $method

Return Value

Form

at line 271
string getMethod()

No description

Return Value

string

at line 280
bool isMethod(string $method)

Checks if the request method is the given one.

Parameters

string $method

Return Value

bool

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

Sets a form-level HTML attribute.

Parameters

string $name
mixed $value

Return Value

Form

at line 299
void allowCrossOrigin()

Disables the SameSite cookie CSRF protection, allowing cross-origin form submissions.

Return Value

void

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

Adds a CSRF protection token field using a SameSite cookie.

Parameters

string|null $errorMessage

Return Value

CsrfProtection

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

Creates a new control group and optionally sets it as current for subsequent addXxx() calls.

Parameters

string|Stringable|null $caption
bool $setAsCurrent

Return Value

ControlGroup

at line 340
void removeGroup(ControlGroup $name)

Removes a group and all its controls from the form.

Parameters

ControlGroup $name

Return Value

void

at line 365
array getGroups()

Returns all defined groups.

Return Value

array

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

Returns the specified group.

Parameters

string|int $name

Return Value

ControlGroup|null

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

No description

Parameters

Translator|null $translator

Return Value

Form

at line 390
Translator|null getTranslator()

No description

Return Value

Translator|null

at line 402
bool isAnchored()

Checks whether the form is attached to a request (always true for standalone forms).

Return Value

bool

at line 411
SubmitterControl|bool isSubmitted()

Returns the submitter control if the form was submitted, or false.

Return Value

SubmitterControl|bool

at line 424
bool isSuccess()

Tells if the form was submitted and successfully validated.

Return Value

bool

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

internal  
 

No description

Parameters

SubmitterControl|null $by

Return Value

Form

at line 444
FileUpload|null getHttpData(int|null $type = null, string|null $htmlName = null)

Returns raw submitted HTTP data for a control, or all form data when called without arguments.

Parameters

int|null $type
string|null $htmlName

Return Value

FileUpload|null

at line 471
void fireEvents()

Fires onSuccess, onError, onSubmit and onClick events based on submission and validation state.

Return Value

void

at line 538
Form reset()

Clears the submission state and resets all control values to defaults.

Return Value

Form

at line 550
protected array|null receiveHttpData()

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

Return Value

array|null

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

No description

Parameters

array|null $controls

Return Value

void

at line 597
void validateMaxPostSize()

internal  
 

No description

Return Value

void

at line 613
void addError(string|Stringable $message, bool $translate = true)

Adds a form-level (not control-level) error message.

Parameters

string|Stringable $message
bool $translate

Return Value

void

at line 627
array getErrors()

Returns all validation errors (own form errors merged with control errors).

Return Value

array

at line 633
bool hasErrors()

No description

Return Value

bool

at line 639
void cleanErrors()

No description

Return Value

void

at line 649
array getOwnErrors()

Returns form-level errors only, excluding control errors.

Return Value

array

at line 661
Html getElementPrototype()

Returns form's HTML element template.

Return Value

Html

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

No description

Parameters

FormRenderer|null $renderer

Return Value

Form

at line 680
FormRenderer getRenderer()

No description

Return Value

FormRenderer

at line 690
protected beforeRender()

No description

at line 698
void fireRenderEvents()

Triggers beforeRender() and onRender events. Must be called before manual rendering (when not using render()).

Return Value

void

at line 708
void render(mixed ...$args)

No description

Parameters

mixed ...$args

Return Value

void

at line 715
string __toString()

No description

Return Value

string

at line 726
array getToggles()

Returns current visibility states of all toggle targets across all controls.

Return Value

array

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

Initializes HTTP request and SameSite CSRF cookie for standalone (non-DI) usage.

Parameters

bool $reinit

Return Value

void