member
Bring membership to the front-end of your site.
For more on how to use these tags together, please read about membership.
Bring membership to the front-end of your site.
For more on how to use these tags together, please read about membership.
Easy to use member login form. Replaces {{ member:login }}
.
{{ member:login_form }}
<input type="text" name="username" id="username" placeholder="Username" >
<input type="password" name="password" id="password" placeholder="Password" >
<input type="submit" value="Log in">
{{ /member:login_form }}
return
— URL to return the user to once logged in, the member
’s configured member_home
by defaultallow_request_return
— when true
, this form will redirect to the return
GET variable if its set, false
by defaultlogged_in_redirect
— where to redirect the user if they’re already logged in, the member
’s configured member_home
by defaultattr
— a way to set other attributes on the generated HTML form
tag, like this: class:my-form|id:login-form
There are a couple of tags available for use within this tag.
error
— Contains any error messages returned by a bad login attemptold_values
— Contains a named-list of values submitted in a bad login attemptUsing the above example, to display an error and the submitted username on a bad login attempt, we use old_values
like this:
{{ member:login_form }}
{{ if error }}
<p class="error">{{ error }}</p>
{{ endif }}
<input type="text" name="username" id="username" placeholder="Username" value="{{ old_values:username }}" >
<input type="password" name="password" id="password" placeholder="Password" >
<input type="submit" value="Log in">
{{ /member:login_form }}
Returns a link that can be used to log out the current member.
<a href="{{ member:logout_url }}">Log Out</a>
Logs a user out of the site.
{{ member:logout }}
return
— URL to return the user to once logged outDisplay information about a given member.
{{ member:profile }}
Your name is {{ first_name }} {{ last_name }}.
{{ /member:profile }}
username
— username of the member’s profile to displayDisplay a form that will create a new member.
{{ member:register_form }}
{{ if error }}
<p class="error">{{ error }}</p>
{{ endif }}
<p>
<label for="username">Username:</label>
<input type="text" name="username" value="{{ old_values:username }}" id="username">
{{ if field_errors:username }}
<br>
<small class="error">{{ field_errors:username }}</small>
{{ endif }}
</p>
<p>
<label for="email">Email:</label>
<input type="text" name="email" value="{{ old_values:email }}" id="email">
{{ if field_errors:email }}
<br>
<small class="error">{{ field_errors:email }}</small>
{{ endif }}
</p>
<p>
<label for="password">Password:</label>
<input type="password" name="password" value="" id="password">
{{ if field_errors:password }}
<br>
<small class="error">{{ field_errors:password }}</small>
{{ endif }}
</p>
<p>
<label for="password_confirmation">Password Again:</label>
<input type="password" name="password_confirmation" value="" id="password_confirmation">
{{ if field_errors:password_confirmation }}
<br>
<small class="error">{{ field_errors:password_confirmation }}</small>
{{ endif }}
</p>
<p>
<input type="submit" name="Submit" value="Sign Me Up">
</p>
{{ /member:register_form }}
return
— an optional URL to redirect members to upon successful profile updating, the user will be returned to the form by defaultallow_request_return
— when true
, this form will redirect to the return
GET variable if its set, false
by defaultattr
— a way to set other attributes on the generated HTML form
tag, like this: class:my-form|id:update-profile-form
error
— contains any whole-form error messages that occur upon submissionsuccess
— contains any whole-form success messages that occur upon submissionfield_errors
— a named-list of fields and the errors that that field generatedold_values
— a named-list of current values to use in the form, will be updated with submitted values after the first submissionsnote Like the
profile_form
tag, the fields available for saving are the ones defined in the member fieldset (found in_config/bundles/member/fields.yaml
). In this file, you can set validation rules, required fields, and fieldtypes to use in the Control Panel. You don’t have to include every field in that list in your{{ member:update_profile }}
form, even fields that are required. When it comes time to validate, Statamic will only validate the fields submitted.
Create a form that lets a member update their profile information.
{{ member:profile_form }}
{{ if error }}
<p class="error">{{ error }}</p>
{{ elseif success }}
<p class="success">{{ success }}</p>
{{ endif }}
<p>
Username: {{ old_values:username }}
</p>
<p>
<label for="first_name">First Name:</label>
<input type="text" name="first_name" value="" id="first_name">
{{ if field_errors:first_name }}
<br>
<small class="error">{{ field_errors:first_name }}</small>
{{ endif }}
</p>
<p>
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" value="" id="last_name">
{{ if field_errors:last_name }}
<br>
<small class="error">{{ field_errors:last_name }}</small>
{{ endif }}
</p>
<p>
<label for="email">Email:</label>
<input type="text" name="email" value="{{ old_values:email }}" id="email">
{{ if field_errors:email }}
<br>
<small class="error">{{ field_errors:email }}</small>
{{ endif }}
</p>
<p>
<input type="submit" name="Submit" value="Update Profile">
</p>
{{ /member:profile_form }}
Like the {{ member:login_form }}
tag, you can use the old_values
variable to display previous information.
On the first load of a page using this form, the information in old_values
will be the current member profile data.
On subsequent submissions (invalid or otherwise), old_values
will contain the last-submitted information.
username
— the username of the member whose profile will be edited, by default it’s the current member, note that only members with at least one of the roles in the member configuration’s edit_other_users
in role_definitions
can edit other member’s information, there is an extra check on submission to enforce thisreturn
— an optional URL to redirect members to upon successful profile updating, the user will be returned to the form by defaultattr
— a way to set other attributes on the generated HTML form
tag, like this: class:my-form|id:update-profile-form
error
— contains any whole-form error messages that occur upon submissionsuccess
— contains any whole-form success messages that occur upon submissionfield_errors
— a named-list of fields and the errors that that field generatedold_values
— a named-list of current values to use in the form, will be updated with submitted values after the first submissionsnote The only fields that will be updated in a member’s profile are the ones defined in the member fieldset (found in
_config/bundles/member/fields.yaml
). In this file, you can set validation rules, required fields, and fieldtypes to use in the Control Panel. You don’t have to include every field in that list in your{{ member:update_profile }}
form, even fields that are rqeuired. When it comes time to validate, Statamic will only validate the fields submitted.
Display a list of members.
<ul>
{{ member:listing }}
<li>{{ first_name }} {{ last_name }}</li>
{{ /member:listing }}
</ul>
role
— limit the members listed to a given role
, false
by default (shows all)limit
— the maximum number of members to display, null
(no limit) by defaultoffset
— the number of members to skip over (after sorting has been applied) before displaying the first members in a listing, 0
by defaultpaginate
— should this tag automatically look for pagination variables in the URL and react accordingly? true
by defaultsort_by
— the field to sort the member list on, title
by defaultsort_dir
— the direction the sorting should happen, either asc
or desc
, desc
by defaultconditions
— works similarly to other listings, you can check for the existence of certain fields, whether a field is equal to a given value, and moreA simple way to paginate through a large listing of members.
<ul>
{{ member:listing sort_by="username" sort_dir="desc" limit="10" paginate="true" }}
<li>{{ first_name }} {{ last_name }}</li>
{{ /member:listing }}
</ul>
{{ member:pagination sort_by="username" sort_dir="desc" limit="10" }}
{{ if total_pages > 1 }}
<p>Page {{ current_page }} of {{ total_pages }}.</p>
{{ if previous_page }}
<p><a href="{{ previous_page }}">Previous page of people</a></p>
{{ endif }}
{{ if next_page }}
<p><a href="{{ next_page }}">Next page of people</a></p>
{{ endif }}
{{ endif }}
{{ /member:pagination }}
Create a form that sends a reset password link.
{{ if logged_in }}
<p>You are already logged in.</p>
{{ else }}
{{ member:forgot_password_form }}
{{ if email_sent }}
<p>Please check your inbox.</p>
{{ else }}
{{ if error }}
<p>{{ error }}</p>
{{ endif }}
<p>
<label for="username">Username:</label>
<input type="text" name="username" id="username" />
</p>
<input type="submit" value="Send me a link" />
{{ endif }}
{{ /member:forgot_password_form }}
{{ endif }}
return
— the url where you will be taken after a successful submissionreset_return
– the url where you will be taken after a successful password reset allow_request_return
— when true
, this form will redirect to the return
GET variable if its set, false
by defaultlogged_in_redirect
— where to redirect the user if they’re already logged inattr
— a way to set other attributes on the generated HTML form
tag, like this: class:my-form|id:login-form
email_sent
- true
after a successful submissionerror
– contains any error message that occur upon submissionnote If your
forgot_password_form
renders nothing, you most likely haven’t set your template path inmember.yaml
.
Create a form that resets a password
{{ member:reset_password_form }}
{{ if url_invalid }}
<p>The URL is invalid. Please click the link in your email.</p>
{{ elseif expired }}
<p>The link is expired</p>
{{ else }}
{{ if errors }}
<div class="errors">
{{ errors|unordered_list }}
</div>
{{ endif }}
<p>
<label for="password">Password:</label>
<input type="password" name="password" id="password" />
</p>
<p>
<label for="password_confirmation">Confirm Password:</label>
<input type="password" name="password_confirmation" id="password_confirmation" />
</p>
<input type="submit" value="Reset" />
{{ endif }}
{{ /member:reset_password_form }}
logged_in_redirect
— where to redirect the user if they’re already logged in, the member’s configured member_home
by defaultattr
— a way to set other attributes on the generated HTML form
tag, like this: class:my-form|id:login-form
errors
– An array of possible errors. You should prevent your form from being shown if there are errors. See sample usage above.note You can specify the return functionality by specifying
reset_return
in the{{ member:forgot_password_form }}
.
This article was last updated on September 13th, 2016. Find an error? Please let us know!