I have a custom form i created using FAPI and i wanted to submit the values into the webform database table and/or content type as a node. i wasnt sure of the "drupal Way" of doin this. Here's my current submit function, Please tell me if im doing this correctly or if not what is the correct way? (P.S. i dont want to use a different r another module or save to my own custom table.)

function contracts_webform_submit($form, &$form_state) {
 module_load_include('inc', 'webform', 'includes/webform.submissions');
 module_load_include('inc', 'webform', 'includes/webform.components');
 global $user;

$node = $form['#node'];
$sid = $form_state['values']['details']['sid'] ? (int) $form_state['values']['details']['sid'] : NULL;

// If there is no data to be saved (such as on a multipage form with no fields
// on the first page), process no further. Submissions with no data cannot
// be loaded from the database as efficiently, so we don't save them at all.
if (empty($submission->data)) {

 // Save the submission to the database.
if (!$sid) {
 // No sid was found thus insert it in the dataabase.
 $form_state['values']['details']['sid'] = $sid = webform_submission_insert($node, $submission);
 $form_state['values']['details']['is_new'] = TRUE;

 drupal_set_message(t('The form has been submitted.'));

1 Answer 1


Without really knowing much else about the custom requirements of your form it's difficult to give a complete answer however your on the right track by using Webform.

You should recreate as much of the form as you can using webform as a base rather than FAPI. Then you can use FAPI to alter (hook_form_alter) the existing form that webform outputs.

Your custom FAPI code can then be worked into the way webform works, you may have to massage some of the data based on your requirements though.

  • i have over 70-odd fields without using webform. im not using webform itself simply becuz the UI is too buggy when used with form_builder on over 70 fields on one form, fields dont render and some fields unecessarily delete. my form is 3 seperate forms attached as fieldsets to a basic info form..mostly all of the fields are simply textfields and select lists..i dont need anything cept the correct way to write a "function mymodule_form_submit or function mymodule_webform_submit" that insert into Webform submissions Commented Mar 28, 2013 at 15:36

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.