Webform save draft after each field update I need to save a draft of the webform after each field change. I know that you can save a draft by clicking a button (or between pages in multi-page forms) and my initial tough was to do a form_alter, add an ajax callback to fields and call the submit handler for save_draft. Had anyone tried something like this?

Some conditions:


If there is an existing draft for the current user, it needs to update that one (not create a new one);
it needs to work for anonymous users as well.


Drupal 7 + Webform 7.x-3.x

I'll post the answer here if I manage to do it, but any feedback would be appreciated if there are people who've done this before.
Ok, I've found this http://drupal.org/node/1319926 and based on it I've managed to make it work. This is my ajax callback (it can be attached using hook_form_alter(), based on your needs):

function _my_module_js_draft($form, &amp;$form_state) {
  global $user;
  $draft_sid = _webform_fetch_draft_sid($form['#node']-&gt;nid, $user-&gt;uid);

  $form_state['values']['details']['sid'] = $draft_sid;
  $form_state['values']['op'] = !empty($form['actions']['draft']['#value']) ? $form['actions']['draft']['#value'] : t('Save Draft');

  $form_state['save_draft'] = TRUE;
  webform_client_form_pages($form, $form_state);
  webform_client_form_submit($form, $form_state);

  return $form;
}


For having the save draft functionality available for Anonymous I've used this patch: http://drupal.org/node/1932560#comment-7185674