Hi all!
I am trying to post from a form to an URL, using cURL. I have managed to do the posting bit, and my data is coming thew to the URL just like I wanted. Here is my code:
<?php
//create array of data to be posted
$post_data['Application.Ssn'] = 'value';
$post_data['Application.Not_Living_Legal_Address'] = 'value';
$post_data['Application.Cellphone'] = 'value';
$post_data['Application.Telephone'] = 'value';
$post_data['Application.Email'] = 'value';
$post_data['Application.Marital_Status'] = 'value';
$post_data['Application.Children_Count'] = 'value';
$post_data['Application.Housing'] = 'value';
$post_data['Application.Tendency'] = 'value';
$post_data['Application.Employment'] = 'value';
$post_data['Application.Employer'] = 'value';
$post_data['Application.Hired_From'] = 'value';
$post_data['Application.Net_Income'] = 'value';
$post_data['Application.Total_Debt'] = 'value';
$post_data['Application.Loans_Debt'] = 'value';
$post_data['Application.Loans_Count'] = 'value';
$post_data['Application.Total_Debt_Expenses'] = 'value';
$post_data['Application.Application_Type'] = 'value';
$post_data['Application.Credit_Limit_Applied'] = 'value';
$post_data['Application.SecretAnswer'] = 'value';
$post_data['Application.SecretQuestion'] = 'value';
$post_data['Application.Heard_About_Us'] = 'value';
$post_data['Application.PPI'] = 'value';
$post_data['Application.Notes'] = 'value';
$post_data['Agreement'] = 'value';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
curl_init('http://www.theurl.com');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
curl_error($curl_connection);
$Response = curl_exec($curl_connection);
curl_close($curl_connection);
return $Response;
?>
Since this is a form the client submitting it needs to get a response right away. The server is sending a response like this, {"Success":false,"Url":null,"Messages":["Sorry, declined"]}
, if the application is being declined. So my question is, how can I get this message threw to the client that have submitted the form? I am very new to this type of coding, so forgive me if my question is not well formulated or missing information.
Thank you in advance for your help!