Kwire
Kwire

Reputation: 107

PHP Post form and return xml result

I have a form which submits to a external url and the url returns a xml result whether the action did go well or not. I want the form to be posted and the xml result to returned so the user can see the xml result instead of the external url being opened in blank window without any formatting.

I'm not sure how to make this.

Upvotes: 0

Views: 205

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270607

Instead of posting the form directly to the external script, you will need to wrap it in your own PHP code to be able to deliver the XML back to your user to view.

To do this, you can:

  1. Make the form post to itself instead of directly to the external resource
  2. Capture the $_POST
  3. Transfer it to a cURL request that posts to the external form
  4. Retrieve the output from the cURL request and display it for your user, wrapped in <pre></pre> to preserve XML formatting.

Note however, that some web browsers will correctly display the returned XML as it already is, provided it is correctly identified as XML by the server sending it. You don't have control over that on either the external server or your end user clients though.

Upvotes: 1

Related Questions