2

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.

UPDATE:

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 ...

  • 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
2

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.

1

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;
}
  • I've updated my begin topic. – nielsv Apr 24 '14 at 16:11
  • 1
    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 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.