Login.Using Custom Fields
What are Custom Fields?
Login supports setting custom (or, "Extended") fields using Revolution's User Profile "extended" field. Basically, MODx stores the field data in a JSON object, which can be retrieved at any time.
Login does it quite simply: using the &useExtended property on the Register, UpdateProfile and Profile snippets. It is set enabled by default.
Usage
Basically, to start using extended fields, all you have to do is add a form field to your Register and UpdateProfile forms. That's it. The snippets will automatically then check for any fields in the POST that aren't in the User table, and if found, store them as extended (custom) fields. They will then be expanded when using the Profile snippet. For example, a Register form that has this in it:
[[!Register? &submitVar=`go`]] ... <label>Favorite Color: <span class="error">[[+error.color]]</span> <input type="text" name="color:required" value="[[+color]]" /> </label> ... <input type="submit" name="go" value="Register!" />
will automatically store the "color" field in the extended fields data. You can even use validators, such as :required as shown here, on the custom field in your Register snippet.
Then, you can use Profile to display this data somewhere on a page:
[[!Profile]] <p>[[+username]]'s Favorite Color: [[+color]]</p>
Or even when using the UpdateProfile snippet:
[[!UpdateProfile]] ... <label>Favorite Color: <span class="error">[[+error.color]]</span> <input type="text" name="color:required" value="[[+color]]" /> </label>
Simple as that!
Directly Creating and Populating Attribute Containers
<input type="hidden" name="january[Spaces]" value="" /> <input type="hidden" name="january[Tables]" value="" /> <input type="hidden" name="january[Chairs]" value="" /> <input type="hidden" name="january[NeedsElectric]" value="" /> <input type="hidden" name="january[Misc]" value="" />
Excluding Fields from Saving as Extended
Both the Register and UpdateProfile snippets have a property called "excludeExtended" that takes a comma-separated list of field names to exclude from being saved as extended fields. So, say you had fields named 'nospam' and 'customProp', that you didn't want to be saved as custom fields in Register. You'd simply call Register like so:
[[!Register? &excludeExtended=`nospam,customProp`]]
In the Manager
Extended fields can also be edited and added from within the Manager, by editing the User and clicking on the "Extended Fields" tab. Make sure if you add fields there, though, that you add them to your UpdateProfile and/or Register forms.
Also, if you have an extended field in a container, such as in this example, where you have test -> boo:
You can access them with the . syntax:
[[!Profile]] Value of nested attribute: [[+test.below]]
...will display 'boo!' there.
See Also
- Login.Login
- Login.Profile
- Login.UpdateProfile
- Login.Register
- Login.ConfirmRegister
- Login.ForgotPassword
- Login.ResetPassword
- Login.ChangePassword
- Login.Tutorials
- Login.Roadmap
Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).