|
<?php // from http://davidwalsh.name/curl-post |
|
require_once( 'infusionsoft-proxy-settings.php' ); |
|
|
|
// extract data from the post |
|
extract($_POST); |
|
|
|
// set POST variables |
|
$fields = array( |
|
'inf_form_xid' => urlencode( $inf_form_xid ), |
|
'inf_form_name' => urlencode( $inf_form_name ), |
|
'infusionsoft_version' => urlencode( $infusionsoft_version ), |
|
'inf_field_FirstName' => urlencode( $inf_field_FirstName ), |
|
'inf_field_LastName' => urlencode( $inf_field_LastName ), |
|
'inf_field_Email' => urlencode( $inf_field_Email ), |
|
'inf_field_Phone1' => urlencode( $inf_field_Phone1 ), |
|
); |
|
|
|
// url-ify the data for the POST |
|
foreach( $fields as $key=>$value ) { |
|
$fields_string .= $key.'='.$value.'&'; |
|
} |
|
rtrim( $fields_string, '&' ); |
|
|
|
// whitelist URLs based on xid |
|
// if this allowed the xid to create any URL, that could be a security hole, allowing anybody to post to whatever URL they want |
|
if ( in_array( $inf_form_xid, $valid_inf_form_xids ) ) { $url = $url_base . 'process/' . $inf_form_xid; } // duplicate this line as needed |
|
|
|
// open connection |
|
$ch = curl_init(); |
|
|
|
// set the url, number of POST vars, POST data |
|
curl_setopt( $ch, CURLOPT_URL, $url ); |
|
curl_setopt( $ch, CURLOPT_POST, count($fields) ); |
|
curl_setopt( $ch, CURLOPT_POSTFIELDS, $fields_string ); |
|
|
|
// downloaded from http://curl.haxx.se/ca/cacert.pem |
|
curl_setopt( $ch, CURLOPT_CAINFO, $ca_bundle_location ); |
|
|
|
// debugging |
|
if ( $debugging ) { |
|
$verbose = fopen( 'php://temp', 'rw+' ); |
|
curl_setopt( $ch, CURLOPT_VERBOSE, true ); |
|
} |
|
|
|
// execute post |
|
$result = curl_exec( $ch ); |
|
|
|
// debugging |
|
if ( $debugging ) { |
|
if ( $result === false ) { |
|
printf( "cURL error (#%d): %s<br/>\n", curl_errno( $ch ) , htmlspecialchars( curl_error( $ch ) ) ); |
|
} |
|
rewind( $verbose ); |
|
$verboseLog = stream_get_contents( $verbose ); |
|
echo "Verbose information:\n<pre>" . htmlspecialchars( $verboseLog ) . "</pre>\n"; |
|
echo 'This script is located at: ' . __FILE__; |
|
} |
|
|
|
// check response for success message |
|
if ( $result != false ) { |
|
header( 'content-type:application/json' ); |
|
return $thank_you_message; |
|
} else { |
|
if ( $debugging ) { var_dump($_POST); } |
|
|
|
$fallback_url = "http://" . $_SERVER['SERVER_NAME'] . str_replace( 'infusionsoft-proxy.php', 'infusionsoft-proxy-fallback.php', $_SERVER['REQUEST_URI'] ) . '?' . http_build_query( $_POST ); |
|
|
|
if ( $debugging ) { echo $get_string; } |
|
|
|
header( 'Location:' . $fallback_url ); |
|
exit; |
|
} |
|
|
|
// close connection |
|
curl_close( $ch ); |
|
?> |
$form.( 'iframe' ).contents().find( 'body' ).append( data );
throwinG : Uncaught SyntaxError: Unexpected token (
Can't get it to work