What is Register?
Register is a registration form processing Snippet. An example call can be found here.
Usage
Simply place the Register snippet in the Resource where your registration form is. (A default one called lgnRegisterForm is provided by the Login 3PC.) This snippet also requires Activation by the User, so they will get an email in their inbox regarding their signup.
Default Properties
Register has some default properties packaged into it. They are:
| Name | Description | Default |
|---|---|---|
| submitVar | The var to check for to load the Register functionality. If empty or set to false, Register will process the form on all POST requests. | login-register-btn |
| usergroups | Optional. A comma-separated list of User Group names or IDs to add the newly-registered User to. | |
| submittedResourceId | If set, will redirect to the specified Resource after the User submits the registration form. | |
| usernameField | The name of the field to use for the new User's username. | username |
| passwordField | The name of the field to use for the new User's password. | password |
| emailField | The name of the field to use for the new User's email address. | |
| successMsg | Optional. If not redirecting using the submittedResourceId parameter, will display this message instead. | |
| activation | Whether or not to require activation for proper registration. If true, users will not be marked active until they have activated their account. Defaults to true. Will only work if the registration form passes an email field. | 1 |
| activationttl | Number of minutes until the activation email expires. Defaults to 3 hours. | 180 |
| activationResourceId | The Resource ID where the ConfirmRegister snippet for activation is located. | 1 |
| activationEmailSubject | The subject of the activation email. | |
| activationEmailTplType | The type of tpls being provided for the activation email. | modChunk |
| activationEmailTpl | The activation email tpl. | lgnActivateEmailTpl |
| preHooks | A comma-separated list of 'hooks', or Snippets, that will be executed before the user is registered but after validation. Also can specify 'recaptcha' as a hook. | |
| postHooks | A comma-separated list of 'hooks', or Snippets, that will be executed after the user is registered. | |
| useExtended | Whether or not to set any extra fields in the form to the Profiles extended field. This can be useful for storing extra user fields. | 1 |
| excludeExtended | A comma-separated list of fields to exclude from setting as extended fields. | |
| persistParams | Optional. A JSON object of parameters to persist across the register process. Useful when using redirect on ConfirmRegister to redirect to another page (eg, for shopping carts). | |
| moderatedResourceId | If a prehook sets the user as moderated, then send to this Resource instead of the submittedResourceId. Leave blank to bypass. | |
| validate | A comma-separated list of fields to validate, with each field name as name:validator (eg: username:required,email:required). Validators can also be chained, like email:email:required. This property can be specified on multiple lines. | |
| customValidators | A comma-separated list of custom validator names (snippets) you plan to use in this form. They must be explicitly stated here, or they will not be run. |
Validators
Validators in Login follow the same syntax as FormIt Validators. You can use the methods described there to use them in your Login-based snippets.
Custom Validators
You can also do custom validators by creating a Snippet and using that as the validator name. You must specify its name in the customValidators property, or it will not be run. Example: We create a Snippet called 'equalTo' and on our field, we set:
<label> Boxes:<span class="error">[[+error.boxes]]</span> <input type="text" name="boxes" id="boxes" value="[[+boxes]]" /> </label>
And in our Register call:
[[!Register? &validate=`boxes:equalTo=^123^` &customValidators=`equalTo` ]]
Now, in our snippet, our code would look like so:
<?php if ($scriptProperties['value'] !== $scriptProperties['param']) { return 'Value not equal to: '.$scriptProperties['param']; } return true; ?>
Returning true will make the field valid. Any other return value will be the error message. Snippets get passed the following parameters in the $scriptProperties array:
- key: The name of the field.
- value: The value of the field.
- param: The parameter, if applicable, passed to the validator.
- type: The name of the validator.
- validator: A reference to the lgnValidator instance.
Post-Validation
After the form has been validated, the Register snippet can do the following:
- Assign the user to usergroups
- Send an activation email
- Redirect to a specific Resource (such as a "Registered!" page)
- or, display a success message.
Assigning User to User Groups
Assigning the User to specified User Groups is easy. Just specify a comma-separated list of either the name of the User Group or the User Group's ID in the "&usergroups" property. This example will assign the User to the "Marketing" and "Research" groups:
[[!Register? &usergroups=`Marketing,Research`]]
Alternatively, you can also specify the Role you would like to add the user to in the User Group by adding it after the User Group name with a colon, like so:
[[!Register? &usergroups=`Marketing:Member,Research:Super User`]]
Sending an Activation Email
Register by default requires the User to activate their account before logging in. The Snippet creates the modUser object and sets its "active" field to 0. The User then gets an email with a URL to activate their account with. Once the User visits the page, their account is set to "active=1", and they can then login.
To enable this, you will need to create an Activation page by creating a new Resource, and putting the ConfirmRegister snippet inside of it.
Next, you'll need to specify an email template chunk to use for the email being sent to the user. An example one is provided with the name: lgnActivateEmailTpl.
An example Register snippet call with activation would look like this:
[[!Register? &activationEmailTpl=`myActivationEmailTpl` &activationEmailSubject=`Please activate your account!` &activationResourceId=`26` &submittedResourceId=`325` ]]
This would send the User the email specified in the "myActivationEmailTpl" chunk, with the specified subject line, which will direct the User to the Resource 26 to activate their account. It will also, after sending the email, redirect the User to a "Please activate your account page" of sorts at Resource 325.
| Activation can be turned off by setting &activation=`0`. Note, though, that this will mean anyone - including spambots - can register and be active users in your site. |
The &activationEmailTpl field can be a chunk name by default. You can change the type of the field by setting &activationEmailTplType to one of the following values:
- modChunk - The default. A name of a chunk.
- file - Specify a filename with an absolute path. You can use {core_path}, {base_path} or {assets_path} as placeholders for this value.
- inline - Specify the html straight in the property value.
| You can also set the time-to-live for an activation email, as well. This will restrict the number of minutes until the activation window expires. You can do this by setting the value in the "activationttl" property. It defaults to 3 hours. |
Redirecting to a Resource After Validation
Redirection is simple: just specify the ID of the Resource to redirect to in the "submittedResourceId" property. For example:
[[!Register? &submittedResourceId=`23`]]
Will redirect to the Resource with ID 23. It will also append "username" and "email" GET parameters to the URL.
Display a Success Message
If the "submittedResourceId" property is not specified, Register will simply display a success message to the [[+error.message]] placeholder. This is the value of the "successMsg" property. For example:
[[!Register? &successMsg=`Thanks for registering!`]]
Will display "Thanks for registering!" in the [[+error.message]] property in the Resource that your [[Register]] snippet call is in after the User submits a valid registration form.