Let's say that I already created a webform with fields Customer Name, Customer Surname and Customer Address.

When the webform is submitted, I want to insert those values captured in a custom table "Customer" created in the database that Drupal is using.

How do I achieve this? Do I have to use a specific module to insert those values?

Is it feasible to do this by using the Rules module? If yes, can you give me a simple example on how to do this?

  • Are you aware that Webform module will store submissions in a table called webform_submissions by default?
    – opdavies
    Apr 18 '16 at 9:55
  • I'm aware of that the data are stored in the submissions but you can also clear all of them. I wanted to find a way to insert data from a webform into a custom table. My goal is to use several tables linked through relationships for a booking system. It'll be hard to retrieve all data from only the webform_submissions table.
    – Joey
    Apr 18 '16 at 12:12

You can use hook_webform_submission_insert to insert data in custom table

ie :

function hook_webform_submission_insert($node, $submission) {
  // Insert a record into a 3rd-party module table when a submission is added.
    'nid' => $node->nid, 
    'sid' => $submission->sid, 
    'foo' => 'foo_data',

As mentioned in above example you will find all submitted data in



  • In the webform module, I added the following db_insert line of codes: db_insert('test')->fields(array(array( 'Name' => $node->webform['components'][1]['value'], 'Surname' => $node->webform['components'][2]['value'], )) ->execute(); within the webform_webform_submission_insert function. It adds a record with empty values. The values of webform['components'][..]['value'] had been checked using devel module. Do you have any idea for this behaviour?
    – Joey
    Apr 18 '16 at 11:57
  • @Joey, i checked with devel : You have to use $submission->data[1][0] value in your insert query instead of $node->webform['components'][1]['value']. Apr 18 '16 at 13:01
  • I used $submission->data[1]['value'] and it works. Thank you very much.
    – Joey
    Apr 19 '16 at 6:12
  • @visabhiushek Where did you check to obtain those values on devel?
    – Joey
    Apr 19 '16 at 6:26
  • @Joey, i have used dsm($submission) and dsm($node) in hook_webform_submission_insert to check the values. There i find $node->webform['components'][1]['value'] is empty and $submission->data[1][0] contains the exact value what we want. Apr 19 '16 at 6:43

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.