By erlendstromsvik on
I need to send data to another page (on another site) using the POST-method.
Earlier I just created an URL, used drupal_goto() and that was it. But now the ability to send data with GET is removed. So instead it seems like I have to use the drupal_goto() to redirect to another local page, which generates a form and then submit this form, with POST-method, to the other site.
I was thinking of using a javascript function, like this, to automatically submit the form on page load:
if(Drupal.jsEnabled) {
$(document).ready(function() {
$('#form-id'.submit());
})
}
Would this be an ok way to do it, or is there some obvious Drupal-magic I've missed?
I can't use cURL, since this is data which should be sent alongside the user/browser...
Comments
Why not cURL?
cURL would be my first choice and should work for POSTing to another site but I do not understand what you mean by "I can't use cURL, since this is data which should be sent alongside the user/browser...". User data needs to be part of the POST since session data is local to the domain so I am not sure what the issue is.
This is for a payment
This is for a payment solution.
The user is taken to an external site to complete a transaction. The data sent with POST is amount and other specific details demanded by the payment solution. On the page for the payment solution the user has to perform a few steps to complete the transaction.
I don't see how cURL can be of any use here. In previous work I've used cURL server side to do "browser related tasks" between servers.
POST the data using cURL or
POST the data using cURL or PEAR's HTTP_Client. You'll then have access to the response data (eg, the HTML the payment site displays after you post the data). Assuming you're doing this from a module page function, just return the HTML and it will be displayed exclusively (eg, no theme).
Drupal magic! This will post
Drupal magic! This will post data to an outside website, save the result as a string then display it. I chose javascript since you seem to be familiar with it. This requires ActiveX, so make sure your users' browsers are not overly secure. Also the XMLHTTP object is for newer browsers, IE7+.
One thing to note is the html references to pictures and such would need to be corrected by parsing the string.
I'm actually quite proud of this script, I sold a prettier version to a real estate investor for $2500 lol
You can replace "POST" with "GET" for GET requests as well.