Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Just exceptional. Thank you so much, Jack, you smashed it.

— Hugo, Developer

User:Profile_Form Tag

Overview

User tags are designed for sites that have areas or features behind a login. The user:profile_form tag helps you build a user profile edit form for existing users based on your user Blueprint.

The tag will render the opening and closing <form> HTML elements for you.

Example

A basic profile edit form, with validation errors.

{{ user:profile_form }}
 
{{ if errors }}
<div class="bg-red-300 text-white p-2">
{{ errors }}
{{ value }}<br>
{{ /errors }}
</div>
{{ /if }}
 
{{ if success }}
<div class="bg-green-300 text-white p-2">
{{ success }}<br>
</div>
{{ /if }}
 
<label>Email</label>
<input type="email" name="email" value="{{ old:email }}" />
 
<label>Bio</label>
<textarea name="bio">{{ old:bio }}</textarea>
 
<label>Job Title</label>
<input type="text" name="title" value="{{ old:title }}" />
 
<button type="submit">Save</button>
 
{{ /user:profile_form }}
 

Blueprints Fields

You may add edit fields for any that exist in the user.yaml blueprint.

Any submitted data that does not exist in the blueprint will be completely ignored.

Additional fields will be validated as per your blueprint validate rules.

Note

The user:profile_form tag doesn't currently support uploading Assets.

Dynamic Rendering

Instead of hardcoding individual fields, you may loop through the fields array to render fields more dynamically.

{{ fields }}
<div class="p-2">
<label>{{ display }}</label>
<div class="p-1">{{ field }}</div>
{{ if error }}
<p class="text-gray-500">{{ error }}</p>
{{ /if }}
</div>
{{ /fields }}
<s:user:profile_form>
 
@foreach ($fields as $field)
<div class="p-2">
<label>{{ $field['display'] }}</label>
<div class="p-1">{!! $field['field'] !!}</div>
@if ($field['error'])
<p class="text-gray-500">{{ $field['error'] }}</p>
@endif
</div>
@endforeach
 
</s:user:profile_form>

Each item in the fields array contains type, display and handle, which are configurable from the user blueprint.

You will also find the field's old input on unsuccessful submission, as well as an error message when relevant.

Finally, the field value contains a pre-rendered form input. Using this will intelligently render inputs as inputs, textareas as textareas, and snozzberries as snozzberries. You can customize these pre-rendered templates by running php artisan vendor:publish --tag=statamic-forms, which will expose editable templates in your views/vendor/statamic/forms/fields folder.

Parameters

redirect

string

Where the user should be taken after successfully saving.

error_redirect

string

The same as redirect, but for failed form submissions.

allow_request_redirect

boolean

When set to true, the redirect and error_redirect parameters will get overridden by redirect and error_redirect query parameters in the URL.

HTML Attributes

Set HTML attributes as if you were in an HTML element. For example, class="required" id="profile-form".

Variables

Variable Type Description

fields

array

An array of available fields for dynamic rendering.

errors

array

An array of validation errors.

error

array

An array of validation errors indexed by field names. Suitable for targeting fields. eg. {{ error:email }}

old

array

An array of previously submitted values.

success

string

A success message.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →