Customizing Registration and Profiles with Custom Fields

| 1 Comment
1.  Create Custom Fields

In System Overview, select Preferences > Custom Fields

Select +New Field

2.  Edit Registration Form

Go to System Overview > Design > Templates > Registration Form

Add this code:

<mt:loop name="field_loop">
<mt:if name="__first__">
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
</mt:if>
<!-- start-customfield_<mt:var name="basename"> -->
<mtapp:setting
id="$field_id"
label="$name"
hint="$description"
shown="$show_field"
show_hint="$show_hint"
required="$required">
<mt:var name="field_html">
</mtapp:setting>
<!-- end-customfield_<mt:var name="basename"> -->
</mt:loop>

Then select Save.

3.  Edit Profile Form

Go to System Overview > Design > Templates > Profile Edit Form

Add the same code as above.

4.  If you only want to display one custom field in certain area on a form, and not all of them in a row, then use If statements.  Here's an example if the custom field you want to use is named "Website Name" with a basename of "website_name".

<mt:if name="field_id" eq="customfield_website_name">
</mt:if>

Your custom field's basename, preceded by "custom field".

Example:

<mt:loop name="field_loop">
<mt:if name="__first__">
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
</mt:if>
<!-- start-customfield_<mt:var name="basename"> -->
<mt:if name="field_id" eq="customfield_website_name">
<mtapp:setting
id="$field_id"
label="$name"
hint="$description"
shown="$show_field"
show_hint="$show_hint"
required="$required">
<mt:var name="field_html">
</mtapp:setting>
</mt:if>
<!-- end-customfield_<mt:var name="basename"> -->
</mt:loop>

Thanks to Aaron Vanderzwan for this last tip.


1 Comment

This is from an email from Beau:

In the View Profile template you can use the example offered when you create the custom field:

<mt:If tag="authordatabio">
Bio: <$mt:AuthorDataBio$>
</mt:If>

Edit Profile template is a little trickier.

You can do basic reordering of fields on the edit profile page (in the app) using the "Reorder Fields" in the related content (or "right") sidebar.

But if you want to place custom fields among default fields you can use the same loop, but limit it to the field(s) you want. There should be a simpler way using the <mt:AuthorCustomFields> block tag, but I couldn't get it to work.

So here's an example of how you can do it.

We use three loops each containing an conditional tag (if or unless) to limit the output of the loop by custom field basename. The first and second loops limit by checking to see if the basename is equal to a value. The third loop outputs all fields except the the two I've specified (be sure not to duplicate fields <wink> )

I'm using the custom fields "Level" and "Bio" in this example. You may place each loop anywhere in the Edit Profile template's form.

<mt:Loop name="field_loop">
<mt:if name="basename" eq="level">
<mt:If name="__first__">
<input type="hidden" name="_type" value="author" id="obj_type" />
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
</mt:If>
<!-- start-customfield_<$mt:Var name="basename"$> -->
<mtapp:setting
id="$field_id"
label="$name"
hint="$description"
shown="$show_field"
show_hint="$show_hint"
required="$required">

<$mt:Var name="field_html"$>

</mt:App:Setting>
<!-- end-customfield_<$mt:Var name="basename"$> -->
</mt:if>
</mt:Loop>

<mt:Loop name="field_loop">
<mt:if name="basename" eq="bio">
<mt:If name="__first__">
<input type="hidden" name="_type" value="author" id="obj_type" />
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
</mt:If>
<!-- start-customfield_<$mt:Var name="basename"$> -->
<mtapp:setting
id="$field_id"
label="$name"
hint="$description"
shown="$show_field"
show_hint="$show_hint"
required="$required">

<$mt:Var name="field_html"$>

</mt:App:Setting>
<!-- end-customfield_<$mt:Var name="basename"$> -->
</mt:if>
</mt:Loop>

<mt:Loop name="field_loop">
<mt:unless name="basename" like="(bio|level)">
<mt:If name="__first__">
<input type="hidden" name="_type" value="author" id="obj_type" />
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
</mt:If>
<!-- start-customfield_<$mt:Var name="basename"$> -->
<mtapp:setting
id="$field_id"
label="$name"
hint="$description"
shown="$show_field"
show_hint="$show_hint"
required="$required">

<$mt:Var name="field_html"$>

</mt:App:Setting>
<!-- end-customfield_<$mt:Var name="basename"$> -->
</mt:unless>
</mt:Loop>

There are definitely some better ways this could be done, but this is the best solution for now.

_beau


Leave a comment

About this Entry

This page contains a single entry by Elise published on September 17, 2008 12:02 AM.

I just finished installing Movable Type 4! was the previous entry in this blog.

Redirects is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.