Movable Type 4.2: Custom Fields on registration / sign up form
This is a blog post about Movable Type development. If you are uninterested in Movable Type development, then you don’t need to read this. I have been working on building a pretty substantial website with Movable Type for the last couple of months and have learned a few things along the way. This is one of those things that I learned that isn’t really documented anywhere. I thought I would try.
The website that I am building allows for users to signup/create usernames/login/post entries/etc. The goal was to require a user, when signing up, to add what company they worked for. This is not one of the standard fields that come with Movable Type’s sign up form (we purchased the Community Solution). What is baked in to Movable Type is the ability to create custom fields on the user object. This is good. It means that we can add as many fields as we want, and associate the data to a specific user, (i.e. Company, Job Title, Birthday, etc.). MT has some documentation on allowing a user to update this custom information on their profile page (http://www.movabletype.org/documentation/community/user-profiles.html). Here is the code they suggest:
<mt:loop name="field_loop">
<mt:if name="__first__">
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
</mt:if>
<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:loop><br />
This is great if you want a user to be able to enter all of the created custom field data at once because it just loops through all of your custom fields and creates input fields for each of them. We had about 10 custom fields on the user object and only wanted the person signing up to enter the ‘Company’ information on signup (as to not make them feel overwhelmed with so much information to input).
How I accomplished only writing one field is to throw an MT if statement in there based on what the $field_id is. In other words what your custom field’s basename is preceded by “customfield_”.
<mt:if name="field_id" eq="customfield_company">
</mt:if>
With “company” my field’s basename, that made the field_id I was looking for, customfield_company.
My final code to display only the company custom field on the user signup form (with MT4.2):
<mt:loop name="field_loop">
<mt:if name="__first__">
<input type="hidden" name="customfield_beacon" value="1" id="customfield_beacon" />
</mt:if>
<mt:if name="field_id" eq="customfield_company">
<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>
</mt:loop><br />
Note: This is only possible on the user registration page after the release of MovableType 4.2. Before that, I think this could only be done on the profile page.
I will update this if I learn any discrepancies in what I said. If you find any, please let me know.
September 18th, 2008 at 2:41 am
Nice work. Once you filter out the fields you want, you can list the remainder by using this conditional and listing the fields you’ve already listed as a pipe separated list in parentheses like this:
<mt:unless name="field_id" like="(customfield_company|customfield_title)">…code here…
</mt:unless>
September 18th, 2008 at 3:16 pm
Thanks Beau. I will look back through my code and see if I can use this anywhere. It might be nice for grouping specific custom fields together.
February 12th, 2010 at 8:53 pm
Just thought i would comment and say neat theme, did you code it yourself? Looks great.
March 6th, 2010 at 1:08 pm
Good information. Tweeted about it. I’ll bookmark this place too.
March 14th, 2010 at 1:38 am
Well, I don’t know if that’s going to work for me, but definitely worked for you!
Excellent post!
March 14th, 2010 at 8:15 pm
Thanks for the post it educated me haha.
March 15th, 2010 at 10:22 pm
Greetings. To start with I want to say that I genuinely like your website, just discovered it the past week but I’ve been following it constantly since then.
I appear to concur with most of your thinkings and beliefs and this submit is no different. absolutely agree with you.
Thank you for the wonderful weblog and I hope you preserve up the good do the job. If you do I will keep on to browse it.
Use a wonderful day.
April 22nd, 2010 at 10:24 pm
Great post! I am sure most people will love this
-Rickie Evey
June 20th, 2010 at 6:30 pm
This is just the sort of info I was looking for! Thanks
July 15th, 2010 at 8:22 am
I have read few of articles here and could say it was really interesting, thanks for sharing this.