Problem/Motivation

If a remote post handler is enabled on a multi page/wizard webform, along with automatic draft saving; the $operation is seen as 'create' when the user clicks the next page button on the first page. This leads to incomplete information being sent to the remote storage.

How to reproduce

  1. Create a webform with multiple pages, and elements on each page
  2. Add a remote post handler and provide a url to store data to
  3. Under 'Allow your users to save and finish the webform later', select 'Authenticated users' and check the box 'Automatically save as draft when paging'
  4. Save and load the form, click the 'Next page' button and check the remote storage

Interim fix

I noticed that the $operation is 'update' when paging between wizard pages, so I created a custom post handler. I added the URL to both 'create' and 'update' options, and added the following code in the post handler. This seemed to fix the issue.


// I removed the namespaces and plugin annotations for brevity.
class WizardPagePostWebformHandler extends RemotePostWebformHandler {

  protected function getPostData($operation, WebformSubmissionInterface $webform_submission) {
    if(!$webform_submission->isCompleted() ){
      return FALSE;
    }
    return parent::getPostData($operation, $webform_submission);
  }

  protected function remotePost($operation, WebformSubmissionInterface $webform_submission) {
    $request_post_data = $this->getPostData($operation, $webform_submission);
    if($request_post_data != FALSE){
      parent::remotePost($operation, $webform_submission);
    }
  }

}

Comments

mattgill created an issue. See original summary.

mattgill’s picture

Issue summary: View changes
jrockowitz’s picture

@mattgill Welcome to the Drupal Community

I wanted the say "Hello" and encourage you to learn more about...

Watch video about helping us help you

@mattgill Are you up for the challenge of contributing your first patch to Drupal.

jrockowitz’s picture

I can see instances where people would like drafts to be posted to a remote server. What is also tricky is the first saving of a draft is being considered an 'insert' by the remote post handler and then when the draft is completed it is treated as an 'update'.

jrockowitz’s picture

We might need to refactor the remote post handler to include a 'draft_url' and 'completed_url'. This would match how the email handler is setup.

It is also important to note that the remote post handler needs better test coverage to make sure we don't break anyones existing implementations.

jrockowitz’s picture

I am going to fix this via #2898424: Improve Remote Post.

jrockowitz’s picture

Status: Needs work » Fixed
mattgill’s picture

Thanks! Sorry I didn't see the notifications for this - will give it a test :)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.