This is an example of PHP server-side code POSTs the web form data to Centerbase using WordPress.
<?php
$error = null;
try {
// We add everything that was posted to the PHP page
$params = array(
'body' => $_POST
);
$params['body']['CbPrivateKey'] = ''; // SPECIFY THE PRIVATE KEY HERE
$params['body']['CbFormId'] = ''; // SPECIFY THE ID OF THE FORM 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
//$params['body']['TestEmail'] = '';
// Post the data to Centerbase using WordPress
// Note: replace test.centerbase.com with your Centerbase site URL (such as MyLawFirm.centerbase.com)
$url = "https://test.centerbase.com/web/webform";
$jsonresult = wp_remote_post($url, $params);
// 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;
}
} 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.