Hi,
I wish to assign a value to the username field of the registration form after it is submitted. Basically I am hiding the username on the form and wish to set it to the value of the email address field on submission. Of course I could user javascript but I was hoping to avoid this.

thanks

G

Comments

Anonymous’s picture

You need to create a module using the code:

<?php
/**
  * Implementation of hook_form_alter().
  **/
function myregistration_form_alter($form_id, &$form) {
  switch ($form_id) {
    case 'user_register':
      unset($form['account']['name']);
      $form['account']['name'] = array(
        '#type' => 'hidden',
        '#value' => user_password(),
      );
    break;
  }
}

/**
  * Implementation of hook_user().
  **/
function myregistration_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'validate':
    global $form_values;
    $form_values['name'] = $form_values['mail'];
    break;
  }
}

// Don't include this closing symbol ?>

I can't take credit for this, I got the information from this forum some time ago but can't remember who posted it. Apologies to the original poster!

VacantPlanets’s picture

thanks you're a life saver