Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Bought Jack McDade's course on design. Going through it now...and it is SO well done!

— Justin Jackson, Transistor.fm

Protect:Password_Form Tag

This tag is used to create a custom content password protection form.

Overview

The HTML of the form itself is up to you. The only requirement is to name the password input password and wrap the form with the tag pair.

Any variables from the protected entry will also be available in the password form.

Example

{{ protect:password_form }}
{{ if invalid_token }}
No token has been provided.
{{ else }}
 
{{ if error }}
<div class="error">{{ error }}</div>
{{ /if }}
 
<input type="password" name="password" />
 
{{ errors:password }}
<div class="inline-error">{{ value }}</div>
{{ /errors:password }}
 
<button>Submit</button>
 
{{ /if }}
{{ /protect:password_form }}
<s:protect:password_form>
@if ($no_token)
No token has been provided.
@else
@if ($error)
<div class="error">{{ $error }}</div>
@endif
 
<input type="password" name="password" />
 
@if (isset($errors['password']))
@foreach ($errors['password'] as $error)
<div class="inline-error">{{ $error }}</div>
@endforeach
@endif
 
<button>Submit</button>
@endif
</s:protect:password_form>

Tokens

When visiting a password protected page, Statamic generates a token and appends it to the form’s URL. Without this token, the form cannot function correctly. This is to combat brute-forcing and bots.

In the example above, you can see the invalid_token boolean will be populated for you. This may happen if you visit the form URL directly.

Parameters

HTML Attributes

string

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

Variables

Variable Type Description

invalid_token

boolean

Returns true when the token is missing or invalid. Functionally the same as the no_token variable.

errors

array

An indexed array of any validation errors upon submission. For example: {{ errors }}{{ value }}{{ /errors }}

error

array

An array of validation errors indexed by field name. For example: {{ error:email }}

old

array

An array of submitted values from the previous request. Used for re-populating fields if there are validation errors.

success

string

A success message that can be used in a condition to check if the password was valid. {{ if success }} Welcome to Narnia! {{ /if }}

HR: Section
Learn More!

There is more to learn more in these related articles:

HR: Section
Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →