Form
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 |
|
validator |
|
| URL |
validator |
| Pattern |
validator |
| PatternInsensitive |
validator |
| Enum |
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 |
|
| EQUAL |
|
| IS_IN |
|
| NOT_EQUAL |
|
| IS_NOT_IN |
|
| FILLED |
|
| BLANK |
|
| REQUIRED |
|
| VALID |
|
| SUBMITTED |
|
| MIN_LENGTH |
|
| MAX_LENGTH |
|
| LENGTH |
|
|
|
|
| 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 |
|
Properties
| $onSuccess | Occurs when the form is submitted and successfully validated |
||
| $onError | |||
| $onSubmit | |||
| $onRender | |||
| internal | $httpRequest | ||
| protected | $crossOrigin | ||
| string[] read-only | $errors | ||
| (string|Stringable)[] read-only | $ownErrors | ||
| Html read-only | $elementPrototype |
Methods
No description
Returns form.
No description
No description
Checks if the request method is the given one.
Sets a form-level HTML attribute.
Disables the SameSite cookie CSRF protection, allowing cross-origin form submissions.
No description
Creates a new control group and optionally sets it as current for subsequent addXxx() calls.
Removes a group and all its controls from the form.
Returns all defined groups.
Returns the specified group.
No description
No description
Checks whether the form is attached to a request (always true for standalone forms).
Returns the submitter control if the form was submitted, or false.
Tells if the form was submitted and successfully validated.
No description
Returns raw submitted HTTP data for a control, or all form data when called without arguments.
Fires onSuccess, onError, onSubmit and onClick events based on submission and validation state.
Internal: returns submitted HTTP data or null when form was not submitted.
No description
No description
Adds a form-level (not control-level) error message.
Returns all validation errors (own form errors merged with control errors).
No description
No description
Returns form-level errors only, excluding control errors.
Returns form's HTML element template.
No description
No description
No description
Triggers beforeRender() and onRender events. Must be called before manual rendering (when not using render()).
No description
No description
Returns current visibility states of all toggle targets across all controls.
Initializes HTTP request and SameSite CSRF cookie for standalone (non-DI) usage.
Details
at line 217
__construct(string|null $name = null)
No description
at line 233
Form|null
getForm(bool $throw = true)
Returns form.
at line 239
Form
setAction(string|Stringable $url)
No description
at line 246
string
getAction()
No description
at line 252
Form
setMethod(string $method)
No description
at line 263
string
getMethod()
No description
at line 272
bool
isMethod(string $method)
Checks if the request method is the given one.
at line 281
Form
setHtmlAttribute(string $name, mixed $value = true)
Sets a form-level HTML attribute.
at line 291
void
allowCrossOrigin()
Disables the SameSite cookie CSRF protection, allowing cross-origin form submissions.
at line 297
void
addProtection(string|null $errorMessage = null)
No description
at line 307
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.
at line 326
void
removeGroup(ControlGroup $name)
Removes a group and all its controls from the form.
at line 351
array
getGroups()
Returns all defined groups.
at line 360
ControlGroup|null
getGroup(string|int $name)
Returns the specified group.
at line 369
Form
setTranslator(Translator|null $translator)
No description
at line 376
Translator|null
getTranslator()
No description
at line 388
bool
isAnchored()
Checks whether the form is attached to a request (always true for standalone forms).
at line 397
SubmitterControl|bool
isSubmitted()
Returns the submitter control if the form was submitted, or false.
at line 410
bool
isSuccess()
Tells if the form was submitted and successfully validated.
at line 419
Form
setSubmittedBy(SubmitterControl|null $by)
| internal |
No description
at line 430
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.
at line 457
void
fireEvents()
Fires onSuccess, onError, onSubmit and onClick events based on submission and validation state.
at line 524
Form
reset()
Clears the submission state and resets all control values to defaults.
at line 536
protected array|null
receiveHttpData()
Internal: returns submitted HTTP data or null when form was not submitted.
at line 570
void
validate(array|null $controls = null)
No description
at line 583
void
validateMaxPostSize()
| internal |
No description
at line 599
void
addError(string|Stringable $message, bool $translate = true)
Adds a form-level (not control-level) error message.
at line 613
array
getErrors()
Returns all validation errors (own form errors merged with control errors).
at line 619
bool
hasErrors()
No description
at line 625
void
cleanErrors()
No description
at line 635
array
getOwnErrors()
Returns form-level errors only, excluding control errors.
at line 647
Html
getElementPrototype()
Returns form's HTML element template.
at line 659
Form
setRenderer(FormRenderer|null $renderer)
No description
at line 666
FormRenderer
getRenderer()
No description
at line 676
protected
beforeRender()
No description
at line 684
void
fireRenderEvents()
Triggers beforeRender() and onRender events. Must be called before manual rendering (when not using render()).
at line 694
void
render(mixed ...$args)
No description
at line 701
string
__toString()
No description
at line 712
array
getToggles()
Returns current visibility states of all toggle targets across all controls.
at line 731
static void
initialize(IRequest $reinit = false)
Initializes HTTP request and SameSite CSRF cookie for standalone (non-DI) usage.