hidden() form()

A hidden input with the value from $replace (or the value option); no row is drawn.

form()->hidden($name, $extra = [], $replace = [])

Options

OptionMeaning
valueValue; default $replace[name].
id, dataAttributes.

Example

<input type="hidden" id="id" name="id" value="42">
<input type="hidden" id="return_to" name="return_to" value="/shop/cart">

Code

$html = (string) form(['id' => 42, 'return_to' => '/shop/cart'])
    ->hidden('id')
    ->hidden('return_to')
    ->text('qty');
return '<pre>' . _prepare_html(implode(PHP_EOL, preg_grep('~name="(id|return_to)"~', explode(PHP_EOL, $html)))) . '</pre>' . $html;

Notes

  • A hidden value comes back as the visitor sends it: check it on the server like any other field.
  • The form adds its own hidden fields: __form_id__ with validation, _token with the CSRF check.

See also: form/input