Hey All,
I have a lead generation business and I'm trying to post the form fill data to my ping tree (with cURL) and then also to Mailwizz DB with the PHP sdk example provided by Twisted.
However it's not working... I can process each of them separately, but when I combine them on the same file it gives me a 200 response but then {error: code:200} or a 400 error as well.
This is my cURL and API code:
Here is the form js processing code as well:
Any help would be greatly appreciated!
thanks Mailwizz fam!
I have a lead generation business and I'm trying to post the form fill data to my ping tree (with cURL) and then also to Mailwizz DB with the PHP sdk example provided by Twisted.
However it's not working... I can process each of them separately, but when I combine them on the same file it gives me a 200 response but then {error: code:200} or a 400 error as well.
This is my cURL and API code:
PHP:
<?php
$email = $_POST['email'];
$first = $_POST['first_name'];
$last = $_POST['last_name'];
/* removed sensitive info */
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'removed sensitive info');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$post = array(
'key' => "emoved sensitive info ",
'campaign' => "removed sensitive info",
'email' => $email,
'first_name' => $first,
'last_name' => $last
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
$result = curl_exec($ch);
$ret = json_decode($result);
$code = $ret->code;
echo $code;
//exit;
curl_close($ch);
if($code == 200){
// require the setup which has registered the autoloader
require_once dirname(__FILE__) . '/setup.php';
//create the endpoint
$endpoint = new MailWizzApi_Endpoint_ListSubscribers();
// ADD SUBSCRIBER
$response = $endpoint->create('removed sensitive info', [
'EMAIL' => $email, // the confirmation email will be sent!!! Use valid email address
'FNAME' => $first,
'LNAME' => $last
]);
$response = $response->body;
$result = $response->itemAt('status');
echo $result;
}
$data = array();
$data['code'] = 200;
$data['data'] = "email=$email&first_name=$first&last_name=$last";
echo json_encode($data);
exit;
Here is the form js processing code as well:
Code:
<script type="text/javascript">
$("#msForm").validate({
rules:{
first_name:"required",
last_name:"required",
email:{email: true,required: true}
},
messages: {
first_name:"This field is required",
last_name:"This field is required",
email:{email:"A Valid Email is required",
required:"Email address is required"
}
},
submitHandler: function(form){
$('#submitBtn').val("Working...");
$.ajax({
url: "curl_and_api.php",
type: 'POST',
data: $('#msForm').serialize(),
success: function(result){
var res = $.parseJSON(result);
if(res.code == 200) {
window.location.href = '../thankyou.php?'+res.data;
return true;
} else {
$(".span7").show();
enableButton();
}
}
});
}
});
</script>
Any help would be greatly appreciated!
thanks Mailwizz fam!