Drupal 7, Webform 3
I want to programmatically submit a webform via drupal_form_submit. However, I'm having difficulty finding a $form_state structure that works. I've submitted my webform via the ui and examined the $form_state variable in my validate callback function, but I still can't get it to work.
My webform has one textfield named "first_name". Below is a snippet of code I've used to test. Whenever I run it, $form_errors is
null. With no errors, I would expect the code to have worked. However, when I check the webform results, it says there are no submissions.
<?php $form_id = 'webform_client_form_55805'; $form_state = array( 'values' => array( 'submitted' => array( 'first_name' => 'David', ), ), ); $node = node_load(55805); $submission = (object) array(); drupal_form_submit($form_id, $form_state, $node, $submission); $form_errors = form_get_errors(); ?>
Am I doing it wrong? Is there a better way? Should I be using webform_client_form_submit instead?
I looked at this Q&A, but it doesn't work for me and seems a bit convoluted: How to submit webform programmatically with Ajax?