views:

47

answers:

4

I am working on a basic HTML page that requires the user to send details to a script located on a third-party website. What I require is for the user to fill out a form on my web page, and have that information submitted to another third-party form.

I do not wish to return anything to the user, other than whether the submission was successful or not. I also do not want the user to have to go to this third-party site to submit using their form.

It was suggested by the website itself to use an iframe and hold its form on your page, but I was wondering what other, preferably better methods are available to me. It'd be nice if there were some form of jQuery/js code I could use to do such a thing.

A: 

Maybe you could try cURL with CURLOPT_POST and CURLOPT_POSTFIELDS?

Im0rtality
+2  A: 

It'd be nice if there were some form of jQuery/js code I could use to do such a thing.

One way is to use jQuery's $.ajax or $.post methods like this:

$.ajax({
  url: url,
  success: function(data) {
    alert('succeeded');
  }
});
Sarfraz
It's surprising that in this day and age it is not easier for someone to just direct it to another script and have it automagically work. Either way, this code appears to be the "best" way to do what's needed so it gets my stamp of approval.
EnderMB
A: 

Do you want like that? It's simple form submitting to another website. But, I can't check whether it's successfully submitted or not.

<form action="http://www.another.com"&gt;
<input name="myInput" type="text">
<input type="submit" value="Submit">
</form>
ppshein
A: 

well it depends if you have control over the other website as well. as in you are able to access the code.

If you are you can use JSONP to pass the values and get a response, but to do it you will have to assign a callback that is sent and then formatted at the front of a JSON object for it to work (they do this for security).

The other option is to use a php ob_start() function. (Note: this will only work if the form you are trying to submit these values to allow $_GET to be used to proccess the form)

        ob_start();
        include('http://wwww.anotherwebsite.com?key1=value1&amp;key2=value2&amp;key3=value3');
        $returnString = ob_get_contents();
        ob_end_clean();

So then from here $returnString is the result, which you can basically search (strpos() to see if true is how I would do it) in php to find key words to see if it was successful or not or what ever you need to check for.

But again, this only works if the form on the remote server uses $_GET and not $_POST (or allows both through globals).

I know this is a php solution, but a warning is that for security purposes, there are serious restrictions on what javascript can do cross server.. the best javascript way to do cross server is JSONP, which jQuery does support so you might want to look into that.. but as I mentioned, for it to work you need to have a callback be able to be sent back with the response, and the response needs to be in a jsonp object format.. (basically you either need to 1. have the other server have a jsonp api for you to use or you have control over the other server's server side files to make the changes needed).

JSD