Advertisement
Guest User

Untitled

a guest
Jul 18th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. function company_form()
  2. {
  3. $form['company_username'] = array(
  4. '#type' => 'textfield',
  5. '#title' => 'company-username',
  6. '#default_value' => '',
  7. '#required'=>'true'
  8. );
  9. $form['company_email'] = array(
  10. '#type' => 'textfield',
  11. '#title' => 'company-email',
  12. '#required'=>'true',
  13. '#default_value' => '',
  14. '#element_validate' => array('generate_special_form_validate'),
  15. );
  16. $form['company_password'] = array(
  17. '#type' => 'textfield',
  18. '#title' => 'company-password',
  19. '#required'=>'true',
  20. '#default_value' => ''
  21. );
  22.  
  23. $form['submit'] = array(
  24. '#type' => 'submit',
  25. '#title' => '',
  26. '#value' => 'Submit',
  27. '#default_value' => ''
  28. );
  29. return $form;
  30. }
  31. function company_form__validate(&$form_state,$form) {
  32.  
  33. if (!valid_email_address($form['input']['email'])) {
  34. form_set_error($form['input']['email'],'Please enter a valid email address.');
  35. }
  36. }
  37. function company_form_submit($form, &$form_state)
  38. {
  39.  
  40.  
  41. global $user;
  42. $company_username = $form_state['input']['company_username'];
  43. $company_email = $form_state['input']['company_email'];
  44. $company_password = $form_state['input']['company_password'];
  45. $fields = array(
  46. 'name' => $company_username,
  47. 'pass' =>$company_password,
  48. 'mail' => $company_email,
  49. 'init' => $company_email,
  50. 'status' => 1,
  51. 'access' => REQUEST_TIME,
  52. 'roles' => array(
  53. 4 => 'company',
  54. ),
  55.  
  56. );
  57. $account=user_save('', $fields);
  58.  
  59.  
  60. if($account->uid)
  61. {
  62. drupal_set_message('User Created SuccessFully');
  63. }
  64.  
  65. }
  66.  
  67. 'roles' => array(
  68. 4 => 'company',
  69. ),
  70.  
  71. /**
  72. * Implements hook_form_BASE_ID_alter()
  73. */
  74. function CUSTOM_MODULE_form_user_register_form_alter(&$form, &$form_state, $form_id) {
  75. // Get the system roles.
  76. $roles = array_map('check_plain', user_roles(TRUE));
  77.  
  78. $form['roles'] = array(
  79. '#type' => 'select',
  80. '#title' => t('Roles'),
  81. '#default_value' => array(),
  82. '#options' => $roles,
  83. );
  84. }
  85.  
  86. /**
  87. * Implements hook_user_insert()
  88. */
  89. function CUSTOM_MODULE_user_insert(&$edit, $account, $category) {
  90. // Save the role if it's set.
  91. if (isset($edit['roles'])) {
  92. // Push the roles to $account object so that user_save can get the role property.
  93. $account->roles[] = $edit['roles'];
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement