Jump to main content Jump to doc navigation

Login.Using Custom Fields

Other versions: 3.x — Found a problem? Please edit this page or report an issue.

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.

Login won't store the field named in the &submitVar property. In this example, "go" wont be stored because it's passed in the &submitVar property.

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

  1. Login.Login
  2. Login.Profile
  3. Login.UpdateProfile
  4. Login.Register
    1. Register.Example Form 1
  5. Login.ConfirmRegister
  6. Login.ForgotPassword
  7. Login.ResetPassword
  8. Login.ChangePassword
  9. Login.Tutorials
    1. Login.Basic Setup
    2. Login.Extended User Profiles
    3. Login.Request Membership
    4. Login.User Profiles
    5. Login.Using Custom Fields
  10. Login.Using Pre and Post Hooks
  11. Login.Roadmap