I am using an API to collect some information. I send a form using POST to the API’s URL.
And it returns XML.
Basically,
<form action="http://api.paythrudev.com/gettoken" method="POST">
<input type="text" name="api_key" value="xxxx"/>
<input type="text" name="api_password" value="xxxx"/>
<input type="text" name="item_name" value="AA"/>
<input type="text" name="item_price" value="12"/>
<p><input type="submit" /></p>
</form>
When i submit this form, it displays XML.
However,
When user clicks submit button, i dont want the user to see the XML but I want the user to be redirected to a page (returning XML has the URL as an element)
How can i achieve this?
- By jquery’s post method?
- Can i achieve this by PHP? without using javascript.
Thanks in advance.
PHP would be your best bet for parsing xml. My main question to you would be whether or not the page that you are posting to resides on your own server or whether or not you are actually bringing your user to a different site altogether (my suspicion is that you are doing the latter).
I would recommend that you have the page post to itself, and then after validating the data that has been submitted then create a http post within the php that sends the necessary variables to the target url. You should be able to receive xml within your php file that way, and since you are still operating in your own domain you can then choose what you want to happen upon receiving the data.
What it boils down to is that it looks like you’re posting to a page that should be used as a web service. Instead of doing that, you need to access the web service from your php file and parse the data there.
Example of parsing xml: http://www.php.net/manual/en/example.xml-structure.php
Can’t find a good tutorial for consuming a web service via php, but I would recommend searching around for “consume web service xml php”
Best regards