0

I've a custom module that generate a form, it allows user to submit some data to website. I'm looking for a nice way to display those submit and I would very much like to use webform module for this (because it is already used a lot in company).

I would appreciate any help especially with some snippets.

I found only this post: Submit a custom form as a webform submission but that is almost nothing.

0

Here's how to create a Webform submission programmatically:

global $user;
$node = node_load(YOUR_NODE_ID);

// Prepare the data. Do note that the keys in this array must match the elements
// in your webform.
$data = array(
  1 => array('Field one value'),
  2 => array('Field two value'),
  3 => array('Field three value'),
);

// Create the submission object.
$submission = new stdClass();
$submission->uid = $user->uid;
$submission->nid = $node->nid;
$submission->submitted = REQUEST_TIME;
$submission->remote_addr = ip_address();
// This is necessary to mark the submission as complete.
$submission->is_draft = FALSE;
$submission->data = $data;

// Store the submission.
module_load_include('inc', 'webform', 'includes/webform.submissions');
webform_submission_insert($node, $submission);

// If necessary, invoke the email sending for this Webform.
webform_submission_send_mail($node, $submission);

Hope this helps.

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.