Skip to content

View Helpers

hiddenFieldTag()

hiddenFieldTag() — returns string

Available in: controller Category: Form Tag Functions

Generates a hidden <input type=“hidden”> tag using a plain name/value pair. Unlike hiddenField(), this helper does not tie to a model object — it’s meant for raw form fields where you control the name and value manually. Note: Pass any additional arguments like class, rel, and id, and the generated tag will also include those values as HTML attributes.

NameTypeRequiredDefaultDescription
namestringyesName to populate in tag’s name attribute.
valuestringnoValue to populate in tag’s value attribute.
encodebooleannotrueEncode URL parameters using EncodeForURL(). Please note that this does not make the string safe for placement in HTML attributes, for that you need to wrap the result in EncodeForHtmlAttribute() or use linkTo(), startFormTag() etc instead.
1. Basic usage
#hiddenFieldTag(name="userId", value=user.id)#

// Generates:
// <input id="userId" name="userId" type="hidden" value="123">

2. With additional attributes
#hiddenFieldTag(
    name="sessionToken",
    value="abc123",
    id="token-field",
    class="hidden-tracker"
)#

// <input id="token-field" name="sessionToken" type="hidden" value="abc123" class="hidden-tracker">

3. Without specifying a value (empty by default)
#hiddenFieldTag(name="csrfToken")#

// <input id="csrfToken" name="csrfToken" type="hidden" value="">

4. Disabling encoding
#hiddenFieldTag(
    name="redirectUrl",
    value="https://example.com/?a=1&b=2",
    encode=false
)#

// <input id="redirectUrl" name="redirectUrl" type="hidden" value="https://example.com/?a=1&b=2">