I have a webform on a Drupal site to which I need to post data programmatically using the following code:
// Get the node ID of the created Webform and load the node.
$node = node_load($nid);
global $user;
$uid = $user->uid;
// Include files.
module_load_include('inc', 'webform', 'webform.module');
module_load_include('inc', 'webform', 'includes/webform.submissions');
// Prepare the data for submission.
$data = array(
2 => array('value' => array('question_id')),
1 => array('value' => array('quiz_name')),
3 => array('value' => array('your_feedback')),
);
$submission = (object) array(
'nid' => $nid,
'uid' => $user->uid,
'submitted' => REQUEST_TIME,
'remote_addr' => ip_address(),
'is_draft' => FALSE,
'data' => $data,
);
print_r($submission);
$sid = webform_submission_insert($node, $submission);
return "Submission {$sid} received!";
The problem is the submission is created but it's entirely empty i:e the $data
array is not represented in the submission.