User Guide & Reference Manual

Members

The account management and user actions in Hero are, by default, bound to specific templates and URL's. This guide outlines those URL's and templates. It also shows you member-related template plugins that can be used throughout your theme, including plugins to create registration forms, login forms, and list site members.

Important URLs

Templates

Member Template Variables

The following variables are available in the {$member} global variable and within a {members} template call (documented below).

Variables
Variable Description
{$id} The member ID.
{$is_admin} Set to TRUE if the user is an administrator, else FALSE.
{$usergroups} An array of usergroups that the user belongs to.
{$first_name}
{$last_name}
{$username}
{$email}
{$signup_date} The date the user signed up on.
{$last_login} The date the user last logged in.
{$suspended} Set to TRUE if the user is suspended, else FALSE.
{$admin_link} A link to the user's profile in the administrator's control panel.
All custom fields for the member are accessible just like the other variables, with the system name of the custom field as the variable name (e.g., {$my_custom_field}).

Specifying a Return URL during Login

This tip is for developers only, or designers who are writing PHP template plugins.

If you want to send users to the main login page at users/login but have them sent back to a specific page when they have logged in, you can specify a return URL with the return query string variable.

This variable must be encoded with the helper function query_value_encode (availably globally).

Example:


<?php
// redirect to login page with specified URL
header('Location: ' . site_url('users/login?return=' . query_value_encode('my_relative_url')));
?>

This URL can also be absolute:


<?php
// redirect to login page with specified URL
header('Location: ' . site_url('users/login?return=' . query_value_encode('http://www.yahoo.com')));
?>

Template Plugins

{login_form}

Display a login form which (optionally) returns the user to a specified URL after a successful login.

Parameters
Variable Required? Description
var Required Specify the name for the returned variable array (e.g., "form" returns an array with keys like {$form.return}.
return No Specify an absolute (e.g., http://www.example.com) or relative (e.g., /members_area) URL to redirect the user to after logging in.
username No Specify the username to auto-populate the username field with. It's highly unlikely that you would pass this parameter, but it is used in system calls.

Available block variables:

Example login form:


{login_form var="login" return=$return}
	<h1>Account Login</h1>
	<form method="post" action="{$login.form_action}">
		<input type="hidden" name="return" value="{$login.return}">
	
		<ul class="form">
			<li>
				<label for="username">Username/Email</label>
				<input type="text" id="username" name="username" value="{$login.username}">
			</li>
			<li>
				<label>Password</label>
				<input type="password" id="password" name="password" />
			</li>
			<li>
				<input type="checkbox" value="1" name="remember" /> Remember me for future visits?
			</li>
			<li>
				<input type="submit" name="login" value="Login" />
			</li>
		</ul>
		
		<ul class="login_form_links">
			<li>
				<a href="{url path="users/register"}">Don't have an account? Click here to register.</a>
			</li>
			<li>
				<a href="{url path="users/forgot_password"}">Forgot your password?</a>
			</li>
		</ul>
	</form>
{/login_form}

{register_form}

Display a register form which (optionally) returns the user to a specified URL after a successful registration.

If you are using custom fields in your registration form, you should set the <form>'s enctype attribute to "multipart/form-data". This is necessary for the form to handle file uploads.
Parameters
Variable Required? Description
var Required Specify the name for the returned variable array (e.g., "form" returns an array with keys like {$form.return}.
return No Specify an absolute (e.g., http://www.example.com) or relative (e.g., /members_area) URL to redirect the user to after registering.

Available block variables:

Example registration form:


{registration_form var="form" return=$return}
	<h1>Create an Account</h1>
	
	<p>Complete the fields below to create your account at {setting name="site_name"}.</p>
	{if $setting.validate_emails == "1"}
		<p>You will be required to validate your email address before your account is fully activated.</p>
	{/if}
	
	<form class="form validate" enctype="multipart/form-data" method="post" action="{$form.form_action}">
		<input type="hidden" name="return" value="{$form.return}">
		
		{if $validation_errors}
			<div class="errors">
				{$validation_errors}
			</div>
		{/if}
	
		<fieldset>
			<legend>Access Information</legend>
			<ul class="form">
				<li>
					<label for="username">Username</label>
					<input type="text" class="text required" id="username" name="username" value="{if $values.username}{$values.username}{/if}">
				</li>
				<li>
					<label for="email">Email</label>
					<input type="email" class="text required" id="email" name="email" value="{if $values.email}{$values.email}{/if}" />
				</li>
				<li>
					<div class="help">After registering, you will be able to login with either your username or your email.</div>
				</li>
				<li>
					<label for="password">Password</label>
					<input type="password" class="text required" id="password" name="password" />
				</li>
				<li>
					<div class="help">Passwords must be greater than 6 characters in length.</div>
				</li>
				<li>
					<label for="password2">Repeat Password</label>
					<input type="password" class="text required" id="password2" name="password2" />
				</li>
			</ul>
		</fieldset>
		
		<fieldset>
			<legend>Profile Information</legend>
			<ul class="form">
				<li>
					<label class="full" for="first_name">First Name</label>
				</li>
				<li>
					<input type="text" class="text required" id="first_name" name="first_name" value="{if $values.first_name}{$values.first_name}{/if}">
				</li>
				<li>
					<label class="full" for="last_name">Last Name</label>
				</li>
				<li>
					<input type="text" class="text required" id="last_name" name="last_name" value="{if $values.last_name}{$values.last_name}{/if}">
				</li>
				{foreach $custom_fields as $field}
					{if $field.name}
						{if $field.type != 'checkbox'}
							<li>
								<label class="full" for="{$field.name}">{$field.friendly_name}</label>
							</li>
							<li>
								{custom_field value=$values[$field.name] field=$field}
							</li>
						{else}
							<li>
								{custom_field value=$values[$field.name] field=$field} <label style="display: inline; float: none" for="field_{$field.name}">{$field.friendly_name}</label>
							</li>
						{/if}
						{if $field.help}
						<li>
							<div class="help flush">{$field.help}</div>
						</li>
						{/if}
					{/if}
				{/foreach}
			</ul>
		</fieldset>
		
		{if $setting.require_tos == "1"}
		<fieldset>
			<legend>Terms &amp; Conditions</legend>
			<textarea style="width: 85%; height: 200px" class="text">{$setting.terms_of_service}</textarea>
			<p>
				<input type="checkbox" value="1" name="agree_tos" /> I agree to the terms and conditions above.
			</p>
		</fieldset>
		{/if}
		
		<input type="submit" class="button" name="go" value="Create Account" />
	</form>
{/registration_form}

{members}

Retrieve data for members matching the passed parameters. This can be used to display a members list, search a members database, or to gather information on administrators or members in other fashions.

Parameters
Variable Required? Description
var Required Specify the name for the returned variable array (e.g., "form" returns an array with keys like {$form.return}.
id No Retrieve a specific member by ID.
email No Search by email address.
username No Search by username.
name No Search by first or last name.
group No Only retrieve users in this particular group (e.g, "2"). You can also join multiple groups like "2|5|6".
custom fields No You can search by any custom member data field. For example, if you have a custom field called "School" with a system name of "school", you can add "school" as a parameter to search by school.

After a {members} call, a {$members_total_count} variable is available for the {paginate} tag to do some pagination.

Example usage:


<table class="table" cellpadding="0" cellspacing="0">
	<thead>
		<tr>
			<td style="width: 25%">Name</td>
			<td style="width: 20%">Company</td>
			<td style="width: 20%">School</td>
			<td style="width: 20%">Chapter</td>
			<td style="width: 15%">Date of Initiation</td>
		</tr>
	</thead>
	<tbody>
		{members var="member" group="3" sort="user_last_name" sort_dir="ASC" limit="100"}
			{assign var="member_id" value=$member.id}
			<tr>
				<td>
					<a href="{url path="members/profile/$member_id"}">{$member.last_name}, {$member.first_name}</a>
				</td>
				<td>
					{$member.company}
				</td>
				<td>
					{$member.school_name}
				</td>
				<td>
					{$member.chapter_name}
				</td>
				<td>
					{$member.year_of_initiation}
				</td>
			</tr>
		{/members}
	</tbody>
</table>

{paginate variable="page" base_url=$current_url total_rows=$members_total_count per_page="100"}