I created:

  • a webform named Test Number checkboxes
  • checkboxes named Number with values one, two and three using Form Builder
  • a table named checkbox_check

Creation of the webform and the checkbox component

Aim: When the webform is submitted, the values selected are placed in a string and saved into the table. Example: If "one" and "two" are selected from the checkboxes, they will be saved like "one,two" in the table when the webform is submitted.

The table name is checkbox_check with field Number (Vachar 11)

EDITED: I just added these codes within the function webform_webform_submission_insert($node, $submission) from the webform.module file in my drupal project:

if($accessnode==11)// the **Test Number checkboxes** webform containing the checkboxes
    $lastestSub=db_query("SELECT MAX(sid) FROM {webform_submitted_data}")->fetchField(); //retrieving the highest number of sid which is the lastest submission
    $selectedData=db_query("SELECT data FROM {webform_submitted_data} WHERE nid = :nid AND cid =:cid AND sid= :sid",array(':nid'=>$accessnode, ':cid' => 1, 'sid'=>$lastestSub))->fetchAll();
    $text='';// This will be used to concatenate the different values into a string and placed in the table afterwards
    foreach($selectedData as $valD)
        'Number' => $text, 

When I submitted the webform, I got this error message:

Error message while running the code

Can you guys help me with this?

  • 1
    One of the variables you're treating as a string is not a string, it's an object - that's as much as can be said from here, we can't see the rest of your code. It's also worth bearing in mind that hacking code in contrib modules is considered bad practice; people might not be too forthcoming in trying to help you make this particular hole any bigger!
    – Clive
    Commented Apr 21, 2016 at 10:14
  • I was thinking exactly what Clive said, and would like to add: Drupal core and contributed modules like Webform expose API functions to do things like storing data, defining form elements, etc. If you build your custom code using the functions and hooks provided by core and contrib, the end result will usually be more stable, more flexible, more secure and easier to maintain. Also you will find it much easier to get support from the community. Commented Apr 21, 2016 at 10:34
  • @Clive I understood your points. It is true that I modified the webform_webform_submission_insert function to add this functionality but I want to work the proper way. Can you guide me? How do I proceed to add this function to an already existing webform without modifying codes in the contrib and core modules?
    – Joey
    Commented Apr 25, 2016 at 7:17
  • @marcangend. You can also answer this question. :)
    – Joey
    Commented Apr 25, 2016 at 7:18
  • I created a custom module. I used the hook hook _webform_submission_insert and rename the function to insert_queries_webform_submission_insert. I placed all the codes in this function and removed the extra codes from the original webform module. It works. Thank you for the advices guys.
    – Joey
    Commented Apr 25, 2016 at 9:45

1 Answer 1


It works if I replace these codes:

$selectedData=db_query("SELECT data FROM {webform_submitted_data} WHERE nid = :nid AND cid =:cid AND sid= :sid",array(':nid'=>$accessnode, ':cid' => 1, 'sid'=>$lastestSub))->fetchAll();

by this:

$selectedData=db_query("SELECT data FROM {webform_submitted_data} WHERE nid = :nid AND cid =:cid AND sid= :sid",array(':nid'=>$accessnode, ':cid' => 1, 'sid'=>$lastestSub))->fetchCol();

Your Answer

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

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