0
votes

I am new to drupal.

I need to customize a registration form by adding fields like id,mobile etc.

Can I accomplish this by creating a custom module?

If yes could anyone please help me with a brief idea on creating and overriding the default user registration submit function. I have to insert these details to another table and also have to pass the data as a service request.

Ive created a custom module with function

module_form_alter(&$form,&$form_state,$form_id){
$form['#submit'] = 'module_form_submit';

if($form_id == 'user_register_form'){ 
        //print_r($form_id);
        $form['email'] = array(
                '#type' => 'textfield',
              '#title' => t('id'),
              '#default_value' => '',
              '#size' => 60,
              '#maxlength' => 15,
              '#required' => TRUE,
         );
    }
}

function module_form_submit($form, &$form_state){
  echo "test";
 exit();
}

module_form_alter is being called and I can see the new field on the registration screen but the submit function is still not called. I need to override the default drupal register submit.

I already have the following function in my theme template.php

function templatename_theme() {
  $items = array();

  $items['user_login'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'portal') . '/templates',
    'template' => 'user-login',
    'preprocess functions' => array(
       'portal_preprocess_user_login'
    ),
  );
  $items['user_register_form'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'portal') . '/templates',
    'template' => 'user-register-form',
    'preprocess functions' => array(
      'portal_preprocess_user_register_form'
    ),
  );
  $items['user_pass'] = array(
    'render element' => 'form',
    'path' => drupal_get_path('theme', 'portal') . '/templates',
    'template' => 'user-pass',
    'preprocess functions' => array(
      'portal_preprocess_user_pass'
    ),
  );

  return $items;
}

user-register-form.tpl.php

    <div class="form-group">
        <?php print drupal_render_children($form); ?>
    </div>

And page--user--register.tpl.php with the html

<div id="login-page">
        <div class="container">     
                 <div class="form-login" >
                <h2 class="form-login-heading"><a href="<?php echo $home; ?>"><img src="<?php echo drupal_get_path('theme', 'portal') . '/images/logo.png'; ?>"  width="100"></a><?php echo $createaccount; ?></h2>
                <div class="login-wrap">
                <?php  
                $elements = drupal_get_form("user_register_form"); 
                $form = drupal_render($elements);
                echo  $form ?>

         <?php if ($messages):?>
            <div id="messages-console" class="clearfix">
                <div class="grid_12">
                    <div class="mt-grid-fix">
                    <?php print $messages; ?>
                    </div>
                </div>
            </div>
            <?php endif; ?>



            </div>
                    </div>

    </div>
  </div>

Is this approach fine or should I change this approach inorder to make my custom module functional?

1
Kindly share what you have tried till now. You start working on it after that if you face issue you can post your code. - Panther
@Panther thanks for your response! I have edited the qsn. - wilNev

1 Answers

2
votes

You can go to:

admin/config/people/accounts/fields

and add the fields that you need.

In the fieldset "User settings" don't forget check "Display on user registration form."

enter image description here