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

ParameterTypeDescription
$namestringThe name attribute for the input element.
$valuestring|int|float|null(optional) The value to be submitted with the form.
$attributesarray(optional) HTML attributes for the input element. Defaults to an empty array ([]).

Return Value

TypeDescription
stringAn 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.