You are here

function _submission_resource_create in Webform Service 7.3

Creates a new webform submission based on submitted values.

Note that this function uses drupal_form_submit() to create new submissions, which may require very specific formatting. The full implications of this are beyond the scope of this comment block. The Googles are your friend.

Parameters

$nid: Node id to which we make submission.

$node: Array representing the attributes a submission add form would submit.

Return value

An associative array contained the new submission id.

See also

drupal_form_submit()

1 string reference to '_submission_resource_create'
webform_service_services_resources in ./webform_service.module
Implements hook_services_resources().

File

./webform_service.inc, line 85

Code

function _submission_resource_create($nid, $submission) {
  $node = node_load($nid);

  // Adds backwards compatability with regression fixed in #1083242
  $submission = _services_arg_value($submission, 'webform_submission');

  // Load the required includes for drupal_execute
  module_load_include('module', 'webform');

  // Prepare form state
  $form_state = array();
  $form_state['values']['submitted'] = $submission;
  $form_state['values']['op'] = variable_get('services_webform_submit_button_resource_create', t('Submit'));

  // Submit form programmatically
  drupal_form_submit('webform_client_form_' . $node->nid, $form_state, $node, array());
  if ($errors = form_get_errors()) {
    return services_error(implode(" ", $errors), 406, array(
      'form_errors' => $errors,
    ));
  }

  // Fetch $sid out of $form_state
  $sid = $form_state['values']['details']['sid'];

  // Only add the URI for servers that support it.
  $submission = array(
    'nid' => $nid,
    'sid' => $sid,
  );
  return $submission;
}