Learn

member

Bring membership to the front-end of your site.

For more on how to use these tags together, please read about membership.

{{ member:login_form }} Added in v1.7

Easy to use member login form. Replaces {{ member:login }}.

Sample Usage

{{ 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 }}

Parameters

  • return — URL to return the user to once logged in, the member’s configured member_home by default
  • allow_request_return — when true, this form will redirect to the return GET variable if its set, false by default
  • logged_in_redirect — where to redirect the user if they’re already logged in, the member’s configured member_home by default
  • attr — a way to set other attributes on the generated HTML form tag, like this: class:my-form|id:login-form

Tags

There are a couple of tags available for use within this tag.

  • error — Contains any error messages returned by a bad login attempt
  • old_values — Contains a named-list of values submitted in a bad login attempt

Using 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 }}

{{ member:logout_url }} Added in v1.7

Returns a link that can be used to log out the current member.

Sample Usage

<a href="{{ member:logout_url }}">Log Out</a>

{{ member:logout }}

Logs a user out of the site.

Sample Usage

{{ member:logout }}

Parameters

  • return — URL to return the user to once logged out

{{ member:profile }}

Display information about a given member.

Sample Usage

{{ member:profile }}
    Your name is {{ first_name }} {{ last_name }}.
{{ /member:profile }}

Parameters

  • username — username of the member’s profile to display

{{ member:register_form }} Added in v1.7

Display a form that will create a new member.

Sample Usage

{{ 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 }}

Parameters

  • return — an optional URL to redirect members to upon successful profile updating, the user will be returned to the form by default
  • allow_request_return — when true, this form will redirect to the return GET variable if its set, false by default
  • attr — a way to set other attributes on the generated HTML form tag, like this: class:my-form|id:update-profile-form

Tags

  • error — contains any whole-form error messages that occur upon submission
  • success — contains any whole-form success messages that occur upon submission
  • field_errors — a named-list of fields and the errors that that field generated
  • old_values — a named-list of current values to use in the form, will be updated with submitted values after the first submissions

note 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.

Read more about membership and registering new members.

{{ member:profile_form }} Added in v1.7

Create a form that lets a member update their profile information.

Sample Usage

{{ 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.

Parameters

  • 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 this
  • return — an optional URL to redirect members to upon successful profile updating, the user will be returned to the form by default
  • attr — a way to set other attributes on the generated HTML form tag, like this: class:my-form|id:update-profile-form

Tags

  • error — contains any whole-form error messages that occur upon submission
  • success — contains any whole-form success messages that occur upon submission
  • field_errors — a named-list of fields and the errors that that field generated
  • old_values — a named-list of current values to use in the form, will be updated with submitted values after the first submissions

note 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.

Read more about membership and profile updating.

{{ member:listing }}

Display a list of members.

Sample Usage

<ul>
    {{ member:listing }}
        <li>{{ first_name }} {{ last_name }}</li>
    {{ /member:listing }}
</ul>

Parameters

  • 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 default
  • offset — the number of members to skip over (after sorting has been applied) before displaying the first members in a listing, 0 by default
  • paginate — should this tag automatically look for pagination variables in the URL and react accordingly? true by default
  • sort_by — the field to sort the member list on, title by default
  • sort_dir — the direction the sorting should happen, either asc or desc, desc by default
  • conditions — works similarly to other listings, you can check for the existence of certain fields, whether a field is equal to a given value, and more

{{ member:pagination }} Added in v1.7

A simple way to paginate through a large listing of members.

Sample Usage

<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 }}

{{ member:forgot_password_form }} Added in v1.9

Create a form that sends a reset password link.

Sample Usage

{{ 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 }}

Parameters

  • return — the url where you will be taken after a successful submission
  • reset_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 default
  • logged_in_redirect — where to redirect the user if they’re already logged in
  • attr — a way to set other attributes on the generated HTML form tag, like this: class:my-form|id:login-form

Tags

  • email_sent - true after a successful submission
  • error – contains any error message that occur upon submission

note If your forgot_password_form renders nothing, you most likely haven’t set your template path in member.yaml.

Read more about resetting passwords

{{ member:reset_password_form }} Added in v1.9

Create a form that resets a password

Sample Usage

{{ 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 }}

Parameters

  • logged_in_redirect — where to redirect the user if they’re already logged in, the member’s configured member_home by default
  • attr — a way to set other attributes on the generated HTML form tag, like this: class:my-form|id:login-form

Tags

  • 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 }}.

Read more about resetting passwords

This article was last updated on September 13th, 2016. Find an error? Please let us know!