0
function lawyer_register_menu() {
  $items['lawyer_register'] = array(
    'title' => 'Lawyer Registration',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'lawyer_register_form'
    ),
    'access callback' => TRUE
  );

  $items['lawyer_register-autocomplete-engine'] = array(
    'page callback' => 'lawyer_register_autocomplete',
    'type' => MENU_CALLBACK,
    'access callback' => TRUE
  );

  return $items;
}
function lawyer_register_form($form, &$form_submit) {
  $form         = array();
  $form['name'] = array(
    '#title' => 'Username',
    '#description' => 'choose a username',
    '#type' => 'textfield',
    '#required' => TRUE
  );

  $form['mail'] = array(
    '#title' => 'email',
    '#description' => 'enter a valid email address',
    '#type' => 'textfield',
    '#required' => TRUE
  );

  $form['fname'] = array(
    '#title' => t('Full Name'),
    '#type' => 'textfield',
    '#size' => 20,
    '#maxlength' => 20
  );

  $form['phone_no'] = array(
    '#title' => t('phone_no'),
    '#type' => 'textfield',
    '#description' => t(''),
    '#size' => 20,
    '#maxlength' => 20
  );

  $form['street_address'] = array(
    '#title' => t('Street Address'),
    '#type' => 'textfield',
    '#size' => 50,
    '#maxlength' => 100
  );



  $form['county'] = array(
    '#title' => t('County'),
    '#type' => 'textfield',
    '#size' => 20,
    '#maxlength' => 20
  );

  $form['send_message'] = array(
    '#type' => 'checkbox',
    '#title' => t('Notify user of new account via email.'),
    '#description' => 'If left unchecked, a message will not be sent.',
    '#default_value' => 1
  );

  $form['submit'] = array(
    '#value' => 'Submit',
    '#type' => 'submit'
  );
  return $form;
}




function lawyer_register_form_submit($form, &$form_submit) {
  $edit    = array(
    'name' => $form_submit['values']['name'],
    'pass' => user_password(),
    'mail' => $form_submit['values']['mail'],
    'init' => $form_submit['values']['mail'],
    'status' => 1,
    'access' => REQUEST_TIME,
    'fname' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $form_submit['values']['fname']
        )
      )
    ),
    'street_address' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $form_submit['values']['street_address']
        )
      )
    ),
    'phone_no' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $form_submit['values']['phone_no']
        )
      )
    ),
    'county' => array(
      LANGUAGE_NONE => array(
        array(
          'value' => $form_submit['values']['county']
        )
      )
    )
  );
  $to      = $form_submit['values']['mail'];
  $subject = 'New account created';
  $headers = "From: [email protected]\nContent-type: text/html";
  $body    = 'A new user account has been created for you at <a  href="http://something.org/">Something.org</a>.<br /> Your login details are as follows:<br />Username: <b>' . $form_submit['values']['name'] . '</b><br /> Password: <b>\'???????\'</b> <br /><br /> Please login to <a  href="http://us.lawandmoney.info">Lawandmoney.org</a> and change your password.<br />';
  if ($form_submit['values']['send_message'] == 1) {
    mail($to, $subject, $body, $headers);
  }
  user_save(drupal_anonymous_user(), $edit);
  drupal_set_message("Successfully Register. Please check your Email for login    details.");

}

here I'm creating customized login registration page working properly. Now I want to send password to user via email so what i can write in message body like for username I write Username: '.$form_submit['values']['name'].' So what can I write for password?

3
  • 2
    I just wanted to ask: are you sure you want to do this? Do you keep in mind that if you send password by email, your user knows it, his ISP knows it, if he read his email via unsecured WiFi in cafe, everyone in that cafe knows it, and so on... In Poland sending password via mail is officially discouraged by authorities and if someone is doing it, is automatically considered guilty if password leaks, for example. Any claims in your code of conduct about "user is responsible for his account" would probably be considered void in court, if you will expose users' password so much.
    – Mołot
    Commented Oct 14, 2014 at 8:00
  • so what can i do for this situation. Commented Oct 14, 2014 at 8:39
  • 1
    Do not send passwords in mail if you want to be able to hold people responsible for their actions. Especially lawyers. Password recovery built in Drupal i is safe in that aspect, for example.
    – Mołot
    Commented Oct 14, 2014 at 8:45

1 Answer 1

3

Store user_password() in a variable. Change your code to this

    function lawyer_register_form_submit($form, &$form_submit)
    {
     $new_password = user_password();
     $edit = array(
      'name' => $form_submit['values']['name'],
      'pass' => $new_password,
      'mail' => $form_submit['values']['mail'],
      'init' => $form_submit['values']['mail'],
      'status' => 1,
      'access' => REQUEST_TIME,
      'fname' => array(LANGUAGE_NONE => array(array('value' => $form_submit['values']   ['fname']))),
      'street_address' => array(LANGUAGE_NONE => array(array('value' =>  $form_submit['values']['street_address']))),
      'phone_no' => array(LANGUAGE_NONE => array(array('value' => $form_submit['values'] ['phone_no']))),
      'county' => array(LANGUAGE_NONE => array(array('value' => $form_submit['values'] ['county']))),
      );
      $to = $form_submit['values']['mail'];
      $subject = 'New account created';
      $headers = "From: [email protected]\nContent-type: text/html";
      $body = 'A new user account has been created for you at <a  href="http://something.org/">Something.org</a>.<br /> Your login details are as follows:<br />Username: <b>'.$form_submit['values']['name'].'</b><br /> Password: <b>'$new_password'</b> <br /><br /> Please login to <a  href="http://us.lawandmoney.info">Lawandmoney.org</a> and change your password.<br />';
       if($form_submit['values']['send_message'] == 1){
         mail($to,$subject,$body,$headers);
         } 
       user_save(drupal_anonymous_user(), $edit);
       drupal_set_message("Successfully Register. Please check your Email for login    deatils.");

     }
12
  • can i add more fields in 'users' table.like fname,street_address,phone_no,county.after adding those fields its affected to drupal or not Commented Oct 14, 2014 at 4:51
  • You cant do this, add fields in accounts settings page, you can find here "admin/config/people/accounts/fields" then you can save with user_save function. And comments in this link it helps you to how to save data in this function api.drupal.org/api/drupal/modules%21user%21user.module/function/… Commented Oct 14, 2014 at 4:58
  • The standard user login registration page i created only for lawyer and add multiple field successfully but for normal user i created this page and insert data into users table.so when i submit this details fname,street_address,phone_no,county are not saved in database Commented Oct 14, 2014 at 5:28
  • How you are saving into user fields ?, in above your code you not saving to any user fields like fname or something. you have save in following format -> 'field_some_custom_field' => array( 'und' => array( 0 => array( 'value' => $new_value, ), ), ), ..... Commented Oct 14, 2014 at 5:49
  • Before saving user_save check the function user_load & check return value object format, then you can understand Commented Oct 14, 2014 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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