Advertisement
Guest User

Untitled

a guest
Feb 1st, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. function MYMODULE_webform_submission_insert($node, $submission) {
  2.  
  3.  
  4. $submitted_data = $submission->data;
  5. $full_name = $submitted_data[1][0];
  6. $user_name = $submitted_data[2][0];
  7. $password = $submitted_data[7][0];
  8. $fmno = $submitted_data[3][0];
  9. $role = $submitted_data[4][0];
  10. $where = $submitted_data[5][0];
  11. $when = $submitted_data[6][0];
  12.  
  13. // For Redirection
  14. variable_set("redirect_to", $role);
  15.  
  16.  
  17. // Need to populate following data for registering the user.
  18. if ( empty($user_name)) {
  19. echo "<h2 style='font-size: 18px; font-family: Helvetica Neue, sans-serif !important; color: #A80C0C; '>No Username Found.</h2>";
  20.  
  21. exit();
  22. }
  23. $user_data = array();
  24. $user_data['init'] = $user_name;
  25. $user_data['mail'] = $user_name;
  26. $user_data['name'] = $user_name;
  27.  
  28. $user_data['field_full_name']['und'][0]['value'] = $full_name;
  29. $user_data['field_fmno']['und'][0]['value'] = $fmno;
  30. $user_data['field_interviewee_role']['und'][0]['value'] = $role;
  31. $user_data['field_where']['und'][0]['value'] = $where;
  32. $user_data['field_when']['und'][0]['value'] = $when;
  33. $user_data['pass'] = $password;
  34. $user_data['status'] = 1;
  35.  
  36. $user_data['roles'] = array(); // You can specify any roles which you need
  37.  
  38.  
  39.  
  40. $tomorrow_date = time() + (60 * 60 * 24);
  41. $date_after_two_days = time() + (60 * 60 * 48);
  42.  
  43. // Check if any previous user with the same email exists?
  44. $previous_user = user_load_by_mail($user_name);
  45.  
  46. if(!empty($previous_user)) {
  47. echo "<h2 style='font-size: 18px; font-family: Helvetica Neue, sans-serif !important; color: #0065bd; '>Another user exists with the same email. Please login or enter another user.</h2>";
  48. }
  49. else {
  50.  
  51. //It'll add a new user here.
  52. $user = user_save('', $user_data);
  53.  
  54. /*
  55. $arr = array ('name'=>$user_name,'pass'=>$password);
  56. // Finalize user login (modify $_SESSION, set login time in db)
  57. user_login_finalize($arr); */
  58.  
  59.  
  60. $form_state = array();
  61. $form_state['uid'] = $user->uid;
  62. //$form_state['redirect'] = 'registration';
  63. user_login_submit(array(), $form_state);
  64. //$new_user = user_load_by_mail($user_name);
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. }
  72.  
  73.  
  74. return theme('register', array('output' => $submission));
  75.  
  76.  
  77. }
  78.  
  79.  
  80. function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  81.  
  82.  
  83. if ($form_id == 'webform_client_form_31') {
  84. $form['#submit'][] = 'my_submit_handler_for_registration';
  85. }
  86. }
  87.  
  88. function my_submit_handler_for_registration(&$form, &$form_state) {
  89.  
  90. $redirecting_to = variable_get("redirect_to");
  91. if($redirecting_to == "McKinsey Solutions") {
  92. $redirecting_to = "frontmso";
  93. }
  94. else {
  95. $redirecting_to = "";
  96. }
  97. $form_state['redirect'] = $redirecting_to;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement