Skip to content

Hidden ​

The Hidden PHP field adds a value to the form data without rendering a visible control. Its frontend presenter is named HiddenInput, and it renders a native <input type="hidden"> only when the field has a name.

Basic Usage ​

php
use InertiaUI\Forms\Fields\Hidden;

Hidden::make('type')->default('contact');
Hidden::make('source')->default('web');
Hidden::make('version')->default(2);

The default method provides the initial form-data value for the hidden field. The generated HiddenInput reads its current value from the form data, so later updates to the package form state stay authoritative.

Model Binding ​

On a form bound to a model or array, the field reads its named value like other PHP fields. The default is used only when the bound data doesn't contain that path, or when a bound model's attribute is null:

php
// In your controller...
$form = EditPostForm::make()->bind($post);

// In your form class...
Hidden::make('user_id')->default(auth()->id());

Nested names use Laravel's normal dotted lookup on the PHP side.

Validation and Conditional Inclusion ​

Hidden fields may still take part in backend validation, authorization, and conditional inclusion:

php
Hidden::make('source')
    ->default('web')
    ->required()
    ->rules(['string', 'in:web,partner'])
    ->visibleWhen('channel', 'online')
    ->clearWhenHidden()
    ->authorizedWhen(fn () => auth()->check());

The rule, rules, required, and nullable methods affect Laravel validation. The authorize, authorizedWhen, and authorizedUnless methods decide whether the field takes part in the form at all. The visibleWhen and hiddenWhen methods decide whether the generated field renderer includes the hidden value. The clearWhenHidden method resets the form-data value to an empty string once the condition excludes the field. See Conditional Visibility, Authorization, and Validation for each API.

The compact Hidden serialization intentionally contains only component, name, an optional visibility, and clearWhenHidden when it's enabled. It has no label, help, error, disabled, readonly, presentation, or interactive precognitive state. The precognitive method is inherited from the base PHP field, but Hidden doesn't serialize it, so it provides no interactive validation trigger.

Hidden uses the shared field APIs for model defaults, validation rules, conditional inclusion, and authorization. It also supports Laravel's when, unless, and tap methods and registered macros as fluent construction utilities.

Using the Component Directly ​

HiddenInput is exported from the components subpath of each package. You may use it for standalone hidden values, or pass it a serialized field while rendering forms manually:

vue
<script setup lang="ts">
import { ref } from 'vue'
import { HiddenInput } from '@inertiaui/form-vue/components'

const source = ref('newsletter')
</script>

<template>
    <HiddenInput
        v-model="source"
        name="source"
        form="signup-form"
        data-testid="signup-source"
    />
</template>
tsx
import { useState } from 'react'
import { HiddenInput } from '@inertiaui/form-react/components'

export function SignupSource() {
    const [source, setSource] = useState<unknown>('newsletter')

    return (
        <HiddenInput
            name="source"
            value={source}
            onValueChange={setSource}
            form="signup-form"
            data-testid="signup-source"
        />
    )
}

Pass a name and bind the value. Native attributes and listeners target the underlying native input. See Native Attributes And Events.