Welcome Guest, Not a member yet? Register   Sign In
Submit to a form on a different site
#1

[eluser]georgeedwards[/eluser]
Hi all, I'm new round here and I just got to say - CodeIgniter absolutely rocks!

But anyway, I have a problem that I've been trying to get my head round for a while.

Is there a where I can submit information to a form on a website I don't own and out of my control (yes I know, not ideal in XSS circumstances), maybe with AJAX or otherwise, and retrieve the output on my own page?

The reason I ask is that I am developing a freight management system for a client who needs to tie in freight track and trace systems from another website into their own. I know how to and have managed to submit information to the other website before simply by creating a <form> on my site with action="http://otherwebsite.com/form/" . But obviously the form on my site redirects to theirs on submit, whereas ideally I would like to pull the information and show it in my interface.

Any ideas anyone could spare would be fantastic - thanks in advance. Smile
#2

[eluser]Wuushu[/eluser]
You could probably curl their form with POST vars. Then process and get the relevant information out of the response. (status, id's, or whatever it is that you're looking for in the form's result)
#3

[eluser]georgeedwards[/eluser]
Hi Wuushu thanks for your reply.

I've just had a play with cURL for an hour or so, it seems very powerful! I'm a bit of a curl newbie, and I've managed to post their form and I get a response back, but I'm getting an entire page in the response, i.e. with <html> etc.

Is there a way at all I can just receive certain information - ideally an array of returned values? I know this seems little optimistic, but I swear I've seen a similar thing somewhere for UPS.
#4

[eluser]Dam1an[/eluser]
You'd probably only be able to get an array back with a proper api. You could always traverse the Dom to get the data that you need
#5

[eluser]georgeedwards[/eluser]
Hi Dam1an, thanks for the reply. Yeah thats what I feared, I emailed the company asking if they have an API I can tap into, but that was a week ago, and they aren't very helpful so hence why I'm looking to go my own way with cURL.

I guessed using regular expressions would have been the only way to do it, but do you think JS would be better?
#6

[eluser]pistolPete[/eluser]
[quote author="georgeedwards" date="1251566657"]... I guessed using regular expressions would have been the only way to do it, ...[/quote]

You could also try a DOM parser like
- http://simplehtmldom.sourceforge.net/
- http://php.net/book.dom


If you post an example of the page you have to parse, we could also help you building that regular expression.
#7

[eluser]Wuushu[/eluser]
To traverse the returned result/DOM I've used phpQuery (http://code.google.com/p/phpquery/) before, and it has not let me down. It works almost identical to the "jQuery" methods.. if you're familiar with that it should not be a big step applying the same logic.
#8

[eluser]georgeedwards[/eluser]
Thanks guys. Well at about the same time that pistolPete posted, I was playing around with simple HTML DOM (found it from Googling) and I must say it's brilliant. Dead easy to use with great docs, and it's much like wuushu describes phpQuery - syntax is very similar to jQuery for traversing the DOM.

Well all in all I got the job done and I've written my own class which acts as an API to this companies tracking system, which uses both cURL to get the POST information, and simple HTML DOM to scrape the bits of information we need into a manageable array.

Thanks again. By the way, if anyone would like to see this code, to help in their projects, or just out of interest, put a post up, and I'll post it. It's relatively simple, a small class of about 200 lines, nothing too complicated, but I'm very pleased with the results! It's the first time I've done something like this!
#9

[eluser]Wuushu[/eluser]
Glad to hear. Good luck with your project and progress, george!




Theme © iAndrew 2016 - Forum software by © MyBB