4

I've been using the String Overrides module to change a few of the text fields in the user/register form. I've found this approach to be simple and effective.

However, I want to insert some text below the "User Account" heading but above the "Email" field. Just some general information about signing up. Unfortunately there is no text there currently so I can't use "String Overrides". Is there a simple way of adding some text? I don't want to create an entire custom registration form and reinvent the wheel, I just want to add some text to the existing form.

2

If you don't want to write your own custom module, you can use the Field Group module. Enable the module and on the Manage fields tab for users, add a Fieldset and then set the description to whatever text/HTML you like. Afterwards, just drag it to the place you want it to appear.

9

You can use hook_form_alter like this.

  function MODULENAME_form_alter(&$form, &$form_state, $form_id){
    switch($form_id) {  
      case 'user_register_form': // the value we stole from the rendered form  
        $form['cutomtext'] = array(
        '#type' => 'item',
        '#markup' => '<div > Your text goes here... </div>',
        '#weight' => 1, // Adjust so that you can place it whereever 
        );
        break;  
    }  
  }

Form API Reference

Also you could try hook_form_FORM_ID_alter

Usage :

function hook_form_FORM_ID_alter(&$form, &$form_state, $form_id) {
  // Modification for the form with the given form ID goes here. For example, if
  // FORM_ID is "user_register_form" this code would run only on the user
  // registration form.

  // Add a checkbox to registration form about agreeing to terms of use.
  $form['terms_of_use'] = array(
    '#type' => 'checkbox',
    '#title' => t("I agree with the website's terms and conditions."),
    '#required' => TRUE,
  );
}
4
  • To do this, I have to create my own module yes?
    – Clinton
    May 1 '12 at 4:38
  • @Clinton Yes of course.
    – niksmac
    May 1 '12 at 5:10
  • 1
    I think hook_form_FORM_id_alter() is more appropriate in this case.
    – ya.teck
    Mar 7 '13 at 3:16
  • @Xio, yes hook_form_FORM_id_alter is better when it comes to performance.
    – niksmac
    Mar 7 '13 at 3:18
2

'#type' => 'item' won't use attribute #value, it should be changed to #markup

function MODULENAME_form_alter(&$form, &$form_state, $form_id){
    switch($form_id) {  
      case 'user_register_form': // the value we stole from the rendered form  
        $form['cutomtext'] = array(
        '#type' => 'item',
        '#markup' => '<div > Your text goes here... </div>',
        '#weight' => 1, // Adjust so that you can place it whereever 
        );
        break;  
    }  
  }

You can also place it in your theme's template.php file. In this case the first line changes to function THEME_form_alter(&$form, &$form_state, $form_id){...

0
0

Possibly a bit late for the OP as he has another solution, but for anyone finding this page from Google, a much simpler way is to create a new block with the required text in and just set it to appear at the top of the main section or in a side bar. This does not get it in between the username and email address, but requires less coding to implement

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.