0

When a user fills out a webform on my Drupal 7 site, on submitting, I need the submission data to be sent over to another database. I'm using hook_webform_submission_insert in a custom module, but I can only get the sid and nid to be inserted into the table. I need my webform fields to be sent also; like first_name, last_name, email, etc. But I get errors upon submitting.

<?php
function hook_webform_submission_insert($node, $submission) {
  // Insert a record into a 3rd-party module table when a submission is added.
  db_insert('mymodule_table')
    ->fields(array(
      'nid' => $node->nid,
      'sid' => $submission->sid,
      'foo' => 'foo_data',
    ))
    ->execute();
}
?>

I've tried 'first_name' => 'first_name', but it doesn't work. What am I doing wrong?

1 Answer 1

2

To get all the submitted data you'll have to go about this a slightly different way. First add an additional submit handler to call a custom function in your module using form alter:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {

    if($form_id == "YOUR_WEBFORM_ID") {
        $form['#submit'][] = 'MYMODULE_additional_insert';
    }
}

Then access the form data and process accordingly from your custom function.

function MYMODULE_additional_insert($form, &$form_state) {

  $data = $form['submitted'];

   // Insert a record into a 3rd-party module table when a submission is added.
   db_insert('mymodule_table')
     ->fields(array(
       'foo' => $data['FOO_FIELD']['#value'],
  ))
  ->execute();

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.