0

Before all else - Here's my current code.

function hook_webform_submission_insert($node, $submission) {

  $password = user_password(8);

  //set up the user fields
  $new_user = array(
    'name' => $form_state['values']['e_mail'],
    'mail' => $form_state['values']['e_mail'],
    'pass' => $password,
    'status' => 0,
    'init' => $email,
    'roles' => array(
      DRUPAL_AUTHENTICATED_RID => 'authenticated user', 
      6 => 'custom role',
    ),
    'field_dealer_fname'=> $form_state['values']['first_name'];
    'field_dealer_lname' => $form_state['values']['last_name'];
    'field_dealer_company' => $form_state['values']['company_name'];
    'field_dealer_phone' => $form_state['values']['phone'];
  );
 $account = user_save(null, $new_user)

    ->execute();
}

I'm very new to Drupal, but intermediate experienced in Web dev in general. I just recently inherited a client from a previous employee before I joined, and he exclusively used Drupal (7, at that.)

Anyways, he previously had a system to set up a new user through this user-submitted webform, but that functionality apparently died 2 months ago in some sort of host migration. Now, I'm trying to figure out a way to accomplish this task with the already existing webform (v 3.27) and database.

That being said, from what I've found, I'm trying to use a webform Submission Hook to call the (Webform) values

first_name,
last_name,
company_name,
phone,
e_mail

to fill the adjacent (Custom) user profile fields of "Dealer_profile" (along with the default ones)

field_dealer_fname
field_dealer_lname
field_dealer_company
field_dealer_phone

So, referring back to my code, my thought process is:

//create a random 8 char password
  $password = user_password(8);

I was thinking this would be the equivalent of saying "these profile values = this user submitted value"

//set up the user fields
  $new_user = array(
    'name' => $form_state['values']['e_mail'],
    'mail' => $form_state['values']['e_mail'],
    'pass' => $password,
    'status' => 0,
    'init' => $email,
    'roles' => array(
      DRUPAL_AUTHENTICATED_RID => 'authenticated user', 
      6 => 'custom role',
    ),
    'field_dealer_fname'=> $form_state['values']['first_name'];
    'field_dealer_lname' => $form_state['values']['last_name'];
    'field_dealer_company' => $form_state['values']['company_name'];
    'field_dealer_phone' => $form_state['values']['phone'];
  );

and ultimately, save this information and execute the hook?

 $account =    user_save(null, $new_user)

    ->execute();

However, I feel like the hook itself is also wrong. This whole hooking thing in Drupal is a little odd to me, coming from mostly Wordpress use. Unfortunately the documentation is a little barebones, or in some way difficult for me to figure out how these things actually work. I was also just kind of thrown into this, and just have to figure everything out! Help is appreciated!

0

First you can add your code and add inside sites\all\modules\webform\includes\webform.submissions.inc in functions named "webform_submission_insert" , and check if it works or not , also as per below image in $submission variable you will get all webform submitted values .

enter image description here

Also , if you want to Get Webfrom submitted data by userid wise use below code anywhere.

module_load_include('inc', 'webform', 'includes/webform.submissions');
$values = webform_get_submissions($nid, null, $user->uid, 1);

if you want to Get Webfrom submitted data by node id , as below code 105 is node id.

module_load_include('inc', 'webform', 'includes/webform.submissions');  
$submissions = webform_get_submissions(105);
| improve this answer | |
  • I'm having trouble visualizing how this should look - i've added the last bit of node-specific code to the top, inserted my code haphazardly into the beginning of webform_submission_insert, and changed $form_state to $submission, just because that made sense at the time. Of course, still no new user being created. Any ideas? – Mackenzie Fritschle Jun 14 '17 at 14:16
  • Hi, You are trying to save your webform submission data and using that field generate new user . right ? – megi Jun 15 '17 at 7:25
  • Yes, that's exactly correct. I haven't been able to find anything that works for me yet. – Mackenzie Fritschle Jun 15 '17 at 14:02
  • Hey, i have checked below code in my project , which will generate new user when you will submit webform . check this img : prntscr.com/flfgck – megi Jun 19 '17 at 5:09
  • as you mention in above question there need modification of user save code as per my screenshot prntscr.com/flfgck , please try this one it will surely work for you. – megi Jun 19 '17 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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