Creating Custom Profile Fields

Once you have enabled the Profile module, you can begin defining custom profile fields by selecting administer > settings > profiles (admin/settings/profile). On this page, you choose a form element to add from the listed elements: a single-line text field, a multiple-line text field, a check box, two types of lists, a URL, and a date. In the example of creating a form to collect information about which instrument someone plays, the best type of form element is a list selection (admin/settings/profile/add/selection), which will allow you to define a list of instruments from which the users can choose. Alternatively, if you want the users to type in the name of their instrument, you could use a single-line text field. Let's assume a list selection element for this example.

Complete the list selection form as follows:

Category: This field is used to name and organize groups of profile fields. Each group will have its own tab added to users' account pages. Each tab will show all of the like-categorized profile fields.

Title: This field is the label for the form element that you are creating. For the instrument-selection example, this should be something like Your instrument.

Form name: This field contains a unique name that Drupal will use to track this information for each user. It must be unique, not only among all of the profile fields you create, but also among the fields internal to Drupal (which you can't possibly be aware of without reading the code). To avoid namespace conflicts with other possible values, the form is prepopulated with profile_. This is intended to be used as a prefix to the name that you give it. While it is not mandatory that you keep to this convention, it is recommended. Add the name of this field after the underscore, without any blank spaces, making sure it is unique. For the instrument example, this could be profile_instrument.

Explanation: Use this field to offer instructions to your users regarding what this particular field is for and what type of information they should be giving you. This is optional and can be omitted if the field name makes it obvious. In the case of a field with the name Your instrument, it is probably safe to say that no additional instructions are needed, so you could leave the Explanation field blank.

Selection options: This field is unique to the list selection type of profile field. The entries correspond to the various options (<option>) that will appear in the selection box (<select>). Enter each option that you wish to offer on its own line. Figure 3-8 shows the values entered in the Selection Options field, as well as the drop-down selection box that is generated from them.

Selection options:

piano cello violin guitar)

A list of all options. Put each option on a separate line. Example options are "red", "blue", "green", etc

Figure 3-8. Selection options and the generated selection box

Weight: This field determines the order in which the custom fields appear.

Visibility: This field deals with the question of whether the field should be publicly visible or private. Private fields are visible only to users with the Administer Users permission. Each user can, of course, see the values in his own profile fields. The Visibility setting also determines whether the information should be listed on pages that list members. The Visibility options include the following:

view edit account settings Instrument

Instrument Instrument:*

view edit account settings Instrument

Instrument Instrument:*

ihorn (v

horn

piano

Delete ]

cello violin guitar

• Hidden profile field, only accessible by administrators, modules, and themes

• Private field, content only available to privileged users

• Public field, content shown on profile page but not used on member list pages

• Public field, content shown on profile page and on member list pages

Page title: For fields where Visibility is set to "Public field, content shown on profile page and on member list pages," you have the option of specifying a page title. Doing so will instruct Drupal to create a special page that lists the users who have entered the same value for this field. This could be useful to list all of the violin players or all of the tuba players on your site, for example. This field can use the placeholder variable %value, which will be replaced with the value that the user chooses for this field. For the profile_instrument, you could set the page title to Plays the %value. For every instrument that you entered for the selection options, there will be a page titled Plays the piano, Plays the guitar, Plays the accordion, and so forth.

The user must enter a value: When checked, this will make the current profile field (profile_instrument, for example) required. The user must enter it in order to submit the profile form. In reality, this makes sense only if the next field is checked as well.

Visible in user registration form: As you can guess, this field determines whether the field appears on the user registration form.

After you complete the form, submit your profile field and try it out! If you checked "Visible in user registration form," you can try creating a new user account by logging out and clicking Create new account (user/register). There, you should see a drop-down selection list of instruments. If you then navigate to the my account page and click edit, you will see a link to the new profile group next to the account settings link.

0 0

Post a comment