1

Users, by default, do not have middle names. So let's say I create a table with a foreign key linking to the user id, this table will contain middle names. How would I tell craft to join the middle name data? Could I create a plugin with a hook that gets middle name whenever user data is pulled? Where do I begin?

3

You can add custom fields to users the same way as you do for entries, categories, and all other elements in Craft. Create a custom field for middle name, and go to Settings > Users > Fields and add that field to the field layout.

EDIT:
The field will show in the profile tab, and there is no way to properly add fields to the account tab, even with a plugin. But, although a bit hacky, you could do this by just moving the field with javascript.

First, install the Control Panel JS plugin by Lindsey DiLoreto. Read the docs on how to get the plugin to load your custom js-file.

Each custom field in the form has an id with the naming convention fields-myCustomFieldHandle-field. If you name the field middleName and want to put it before the email field on the account tab, you could do something like this:

$(function () {
    if ($('#userform').length>0) { // just to make sure we're in the user edit page
       $('#email-field').before($('#fields-middleName-field'));
    }
});

Getting it to appear between the first and last name fields, or making them 100% width and putting the middlename in the middle, would also be possible, but requires a bit more DOM manipulation. Let me know if this is important for you.

3
  • Thanks for the reply. I did figure this much out but preferably the new "middle name" field would display under the account tab instead of the profile tab. My assumption is this would have to happen via a plugin. Am I right or is there some other avenue I should take? If this should be done with a plugin can you give me some direction? I'm a newbie to Craft CMS.
    – Matt V
    Feb 19 '15 at 20:21
  • 1
    @MattV I don't think it's possible to add extra fields to the account tab, even with a plugin.
    – carlcs
    Feb 19 '15 at 20:44
  • 1
    @MattV I've updated my answer with a javascript solution for moving the field into the account tab. Feb 19 '15 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.