Home > OS >  How can I deal with the response to a POST request sent to my website from an external webserver?
How can I deal with the response to a POST request sent to my website from an external webserver?

Time:10-29

Here is my situation. I have a webserver running a PHP MVC app. I have various HTML forms that the user can fill out and submit, which generate a POST request, and my website responds with a page acknowledging the data sent in the POST, all good.

Now we have a situation where we want to have a PDF form with fillable fields. I can use Acrobat to put fillable fields directly in the PDF, and add a Submit button that will cause Acrobat to generate a POST request back to my website (the URL is embedded in the Submit action in the PDF). This works fine, except that it requires the end user to download the form to their computer and open it in Acrobat. Although web browsers can typically display PDF forms, and allow the user to fill in fields just fine, the submit button does not work. And when using Acrobat, the response to the POST sent by Acrobat to my webserver, of course goes back to Acrobat, so it gets rendered in a new tab in Acrobat, not in the browser that the user used to download the PDF. Sort of okay, but not a great user experience.

There are websites like formrouter.com and goformz.com that let you define fillable fields on a PDF that you upload, and provide you with a public URL where end users can fill out the form and submit it. At the moment at least, the person creating the form has some options for what the Submit button should do, but neither one of them offers an option to send a POST request to a specified URL. I'm talking to the folks at goformz to see if they would add such a feature, making it more "feature compatible" with Acrobat.

But the problem with having another website like goformz.com send a POST request to my website is simply what to do with my website's response. It doesn't make sense for them to try to render it in their goformz tab in the user's browser. And I don't see how my website can do anything about it in the tab that the user has open on my website that they started from. I guess I could open the goformz page in an iframe, and simply tell the user to close the iframe after they submit the form, but I don't think that a response coming back to that iframe can affect the containing window in any way, can it? AFAIK, it wouldn't really be any better than opening the goformz page in a new browser tab.

Does this make sense? Any suggestions?

Goformz does currently offer an option for the Submit button to email the completed form to an address specified by the form creator, so as an alternative to the POST request, I could have the submit button send the PDF as an attachment to an email to a specific address on my server, and have the server monitor that inbox and process the form data appropriately. But the HTTP response to pressing the Submit button could at most be to acknowledge that an email was sent from goformz.com, the response to the web browser could not contain any information about the form values produced by my website. Any information like that would have to be sent back to the user by email - or is a "push notification" something that could work in this situation? If so, I suppose a "push notification" would also work for sending the response to the POST request made to my website back to the user who clicked the Submit button on the goformz website. I guess this shows that I know nothing about "push notifications". I just heard they were a really cool feature of mobile apps, but that modern browsers could also do them...

BTW, I asked this on SuperUser, but it was closed as off-topic. I hope it's on-topic here, cause I couldn't find a more appropriate Stack Exchange site...

CodePudding user response:

ISSUE :

The JS in Acrobat knows the DOM of the PDF while the JS in WebBrowsers will not know that.
Moreover the JS in Acrobat can not control the WebBrowser tabs because it can not know about the WebBrowser itself.
That is why the Current Workflow is to manually Print (& Mail it over) or Download (& Email it over) which avoids the given Issue.

POSSIBLE SOLUTION :

If you want to change that Workflow , then :

  • You should make Equivalent HTML5 to look like the PDF
  • When the user clicks Submit , you can validate it with JS
  • Then WebBrowser will POST it to your WebServer
  • Now your WebServer can store the Data & Process it
  • Your WebServer can then generate a PDF to show in a new tab which will also avoid the given Issue.

Available tools :

https://www.idrsolutions.com/online-pdf-to-html5-converter  
https://www.zamzar.com/convert/pdf-to-html5/  
https://www.adobe.com/acrobat/hub/how-to/how-to-convert-pdf-to-html  
https://document.online-convert.com/convert/pdf-to-html5  

You might want to try that.

  • Related