This is an example of PHP server-side code POSTs the web form data to Centerbase using cURL.
<?php
$error = null;
try {
// Initialize a cURL request
$ch = curl_init();
// Add the Centerbase Form ID and Private Key to the POST data that came from the form
$postdata = $_POST; // We add everything that was posted to the PHP page
$postdata["CbFormId"] = ""; // SPECIFY THE ID OF THE FORM HERE
$postdata["CbPrivateKey"] = ""; // SPECIFY THE PRIVATE KEY HERE
// Uncomment this and add your e-mail address in order to test your code
// If Centerbase receives the form data successfully, it will send you an e-mail showing the data it was sent instead of adding records to Centerbase
//$postdata["TestEmail"] = "myemail@fakemail.com";
// Setup the cURL configuration
$curlConfig = array(
// The URL to POST to
CURLOPT_URL => "https://test.centerbase.com/web/webform" // // Note: replace test.centerbase.com with your Centerbase site URL (such as MyLawFirm.centerbase.com)
// Tells it to make a POST request
,CURLOPT_POST => true
// Tells it to return the results, not just output them
,CURLOPT_RETURNTRANSFER => true
// Specifies the fields to POST.
,CURLOPT_POSTFIELDS => $postdata
// Specifies that we don't want cURL to verify the peer, which allows us to transmit over SSL
,CURLOPT_SSL_VERIFYPEER => false
);
// Set the options and execute the request
curl_setopt_array($ch, $curlConfig);
$jsonresult = curl_exec($ch);
if (curl_errno($ch) > 0) {
// If there was a cURL error, get the error string
$error = curl_strerror(curl_errno($ch));
}
else {
// Decode the JSON result
$result = json_decode($jsonresult);
// If Centerbase said it was successful, we are good to go
if ($result->success) {
echo 'It Worked!'; // PUT ANY CODE HERE THAT YOU WANT RUN IF THERE WERE NO ERRORS
}
else {
// Otherwise, get the error Centerbase returned
$error = $result->error;
}
}
// Close the cURL connection
curl_close($ch);
} catch (Exception $e) {
// Catch the exception and note the error
$error = $e->getMessage();
}
// If there was an error, show it now
if (!is_null($error)) {
echo $error; // PUT ANY CODE HERE THAT YOU WANT RUN IF THERE WAS AN ERROR
}
?>
Comments
0 comments
Please sign in to leave a comment.