Form
class Form extends Container implements HtmlStringable
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 |
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 |
internal TRACKER_ID |
|
internal PROTECTOR_ID |
|
Properties
$onSuccess | Occurs when the form is submitted and successfully validated |
||
$onError | |||
$onSubmit | |||
$onRender | |||
internal | $httpRequest | ||
protected | $crossOrigin | ||
string | $action | ||
string | $method | ||
array read-only | $errors | ||
array read-only | $ownErrors | ||
Html read-only | $elementPrototype | ||
FormRenderer read-only | $renderer |
Methods
No description
Returns self.
Returns form's action.
Returns form's method.
Checks if the request method is the given one.
Changes forms's HTML attribute.
Disables CSRF protection using a SameSite cookie.
Cross-Site Request Forgery (CSRF) form protection.
Adds fieldset group to the form.
Removes fieldset group from form.
Returns all defined groups.
Returns the specified group.
Sets translate adapter.
Returns translate adapter.
Tells if the form is anchored.
Tells if the form was submitted.
Tells if the form was submitted and successfully validated.
Sets the submittor control.
Returns submitted HTTP data.
Fires submit/click events.
Internal: returns submitted HTTP data or null when form was not submitted.
Performs the server side validation.
No description
Adds global error message.
Returns global validation errors.
No description
No description
Returns form's validation errors.
Returns form's HTML element template.
Sets form renderer.
Returns form renderer.
No description
Must be called before form is rendered and render() is not used.
Renders form.
Renders form to string.
No description
Initialize standalone forms.
Details
at line 127
__construct(string|null $name = null)
No description
at line 146
Form|null
getForm(bool $throw = true)
Returns self.
at line 155
Form
setAction(string|Stringable $url)
Sets form's action.
at line 165
mixed
getAction()
Returns form's action.
at line 174
Form
setMethod(string $method)
Sets form's method GET or POST.
at line 188
string
getMethod()
Returns form's method.
at line 197
bool
isMethod(string $method)
Checks if the request method is the given one.
at line 206
Form
setHtmlAttribute(string $name, mixed $value = true)
Changes forms's HTML attribute.
at line 216
void
allowCrossOrigin()
Disables CSRF protection using a SameSite cookie.
at line 225
CsrfProtection
addProtection(string|null $errorMessage = null)
Cross-Site Request Forgery (CSRF) form protection.
at line 236
ControlGroup
addGroup(string|Stringable|null $caption = null, bool $setAsCurrent = true)
Adds fieldset group to the form.
at line 255
void
removeGroup(ControlGroup $name)
Removes fieldset group from form.
at line 280
array
getGroups()
Returns all defined groups.
at line 289
ControlGroup|null
getGroup(string|int $name)
Returns the specified group.
at line 301
Form
setTranslator(Translator|null $translator)
Sets translate adapter.
at line 311
Translator|null
getTranslator()
Returns translate adapter.
at line 323
bool
isAnchored()
Tells if the form is anchored.
at line 332
SubmitterControl|bool
isSubmitted()
Tells if the form was submitted.
at line 345
bool
isSuccess()
Tells if the form was submitted and successfully validated.
at line 355
Form
setSubmittedBy(SubmitterControl|null $by)
internal |
Sets the submittor control.
at line 365
mixed
getHttpData(int|null $type = null, string|null $htmlName = null)
Returns submitted HTTP data.
at line 388
void
fireEvents()
Fires submit/click events.
at line 454
Form
reset()
Resets form.
at line 465
protected array|null
receiveHttpData()
Internal: returns submitted HTTP data or null when form was not submitted.
at line 498
void
validate(array|null $controls = null)
Performs the server side validation.
at line 511
void
validateMaxPostSize()
internal |
No description
at line 527
void
addError(string|Stringable $message, bool $translate = true)
Adds global error message.
at line 540
array
getErrors()
Returns global validation errors.
at line 546
bool
hasErrors()
No description
at line 552
void
cleanErrors()
No description
at line 561
array
getOwnErrors()
Returns form's validation errors.
at line 573
Html
getElementPrototype()
Returns form's HTML element template.
at line 588
Form
setRenderer(FormRenderer|null $renderer)
Sets form renderer.
at line 598
FormRenderer
getRenderer()
Returns form renderer.
at line 608
protected
beforeRender()
No description
at line 616
void
fireRenderEvents()
Must be called before form is rendered and render() is not used.
at line 629
void
render(...$args)
Renders form.
at line 639
string
__toString()
Renders form to string.
at line 646
array
getToggles()
No description
at line 663
static void
initialize(bool $reinit = false)
Initialize standalone forms.