class FormStateService (View source)

Service class for managing form state across requests

This service handles storing and retrieving form data when validation errors occur, allowing form fields to retain their values after a failed submission.

Constants

private SESSION_KEY

private EXPIRY_TIME

Methods

void
saveFormData(string $formId, array $data)

Save form data to the session with an expiry time

array|null
getFormData(string $formId)

Get form data from the session without removing it

void
clearFormData(string $formId)

Explicitly clear form data when it's no longer needed

string
generateFormId(string $prefix = '')

Generate a unique form ID based on the current request

string|null
getLatestFormId(string $prefix)

Get the latest form ID with a specified prefix

Details

void saveFormData(string $formId, array $data)

Save form data to the session with an expiry time

Parameters

string $formId

Unique identifier for the form

array $data

Form data to store

Return Value

void

array|null getFormData(string $formId)

Get form data from the session without removing it

Parameters

string $formId

Unique identifier for the form

Return Value

array|null

The form data or null if it doesn't exist or has expired

void clearFormData(string $formId)

Explicitly clear form data when it's no longer needed

Parameters

string $formId

Unique identifier for the form

Return Value

void

string generateFormId(string $prefix = '')

Generate a unique form ID based on the current request

Parameters

string $prefix

Optional prefix for the form ID

Return Value

string

The generated form ID

string|null getLatestFormId(string $prefix)

Get the latest form ID with a specified prefix

Parameters

string $prefix

The prefix to search for

Return Value

string|null

The latest form ID or null if none found