Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to add some titles in my registration form. This is a part of my registration form:

enter image description here

But now I would like to have some titles like the following:

enter image description here

I know that you can alter the registration form like this:

function mytheme_form_user_register_form_alter(&$form, &$form_state, $form_id) {


But I don't know which attributes or ... to use.


I'm now trying out the markup.

This is what I do:

function xmed_form_user_register_form_alter(&$form, &$form_state, $form_id) {
    $form['account']['mail'] = array(
        '#markup' => '<p>testtttinnng</p>',
        '#weight' => 116

But this just replaces my email content ...

share|improve this question
I would suggest to use Contributed module instead of writing custom code.. It will be easy to maintain in future.. For example if you add more fields later you need to change weights and grouping them will become difficult.. Field Group module is the best way to go ... – Anil Sagar Apr 24 '14 at 16:14
up vote 2 down vote accepted

You can use Field group Contributed module...

Project page says..

Fieldgroup will, as the name implies, group fields together. All fieldable entities will have the possibility to add groups to wrap their fields together. Fieldgroup comes with default HTML wrappers like vertical tabs, horizontal tabs, accordions, fieldsets or div wrappers.

share|improve this answer

You have several alternatives:

  • Use #markup element. The markup element you can add arbitrary HTML to the form. Just place your markup in the right place using the #weight attribute (form elements are sorted by this value).

  • Use a fieldset element, wrap your element inside and theme that fieldsets. you can create a fieldset for every header and then move the form elements inside each corresponding fieldset.

  • Use the #prefix and/or #suffix element's attributes, where you can also put HTML code.

Example using the markup:

function xmed_form_user_register_form_alter(&$form, &$form_state, $form_id) {

    $form['account']['pre_mail_markup'] = array(
        '#markup' => '<p>testtttinnng</p>',
        '#weight' => 100

    $form['account']['mail']['#weight'] => 105;
share|improve this answer
I've updated my begin topic. – nielsv Apr 24 '14 at 16:11
You are confused by the markup element and the markup attribute. Check my example in the edited answer. But I agree with Anil Sagar that for your problem it may be better to use the contributed module Field group, it's a nice module. – sanzante Apr 24 '14 at 16:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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