Cross-domain form POST using PHP
So here's the problem: you have an event registration form on your site, and within that form is a checkbox saying "add me to your mailing list". If this checkbox is selected, the user must automatically be added to your client's e-mail newsletter list which is run by Mail Chimp.
The problem here is that the form needs to be submitted both to your own site (so that the user is registered for the event) and also to the third party - Mail Chimp ... simultaneously.
Ordinarily when submitting a form to two places I might make an Ajax call using the POST method for one of the submissions. Unfortunately this doesn't work in this case because JavaScript (and hence Ajax) doesn't allow calls to be made between different domains.
The solution, provided you are using PHP and your server has it installed, is the PHP cURL library.
Sticking with our Mail Chimp example, modify the following code as you require, and place it inside the PHP script used to catch the form POST event:
// set up the POST values to send to Mail Chimp
$postArray = $_POST;
$postArray['u'] = 'your Mail Chimp "u" value';
$postArray['id'] = 'your Mail Chimp form ID';
// send data to Mail Chimp using cURL
$curl = curl_init();
$curlOptions = array(
CURLOPT_URL => 'your Mail Chimp form URL',
CURLOPT_POST => TRUE,
CURLOPT_POSTFIELDS => $postArray,
CURLOPT_HEADER => FALSE,
CURLOPT_RETURNTRANSFER => TRUE
);
curl_setopt_array ( $curl, $curlOptions );
curl_exec( $curl );
curl_close( $curl );
This code is self-contained so will not affect anything else in the PHP script. Also, note that you can output the contents of the target (third-party) page by echoing the curl_exec() line (or assigning it to a variable and outputting elsewhere).
Modify as required for other purposes!