form_hidden()
function form_hidden(string $name, string|int|float|null $value = null, array $attributes = []): string
Description
Generates a hidden input field for storing data that should not be visible to users but is submitted with the form.
Parameters
| Parameter | Type | Description |
|---|---|---|
| $name | string | The name attribute for the input element. |
| $value | string|int|float|null | (optional) The value to be submitted with the form. |
| $attributes | array | (optional) HTML attributes for the input element. Defaults to an empty array ([]). |
Return Value
| Type | Description |
|---|---|
| string | An HTML hidden input element. |
Example #1: Basic Hidden Field
Example #2: Hidden Field for User ID
Example #3: Multiple Hidden Fields
Security: Hidden fields are visible in page source. Never store sensitive data like passwords.
Notes
- Hidden fields are not displayed to users but are included in form submissions.
- Common uses: CSRF tokens, record IDs, tracking data, preserving state between requests.
- Values can be strings, integers, or floats - all are converted to strings in HTML.
- Access submitted values with
post('field_name', true). - For sensitive data, use session variables instead of hidden fields.