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
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 |
errors |
array |
An indexed array of any validation errors upon submission. For example: |
error |
array |
An array of validation errors indexed by field name. For example: |
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. |