Wordpress Registration Checkbox with Sendy API
Hi, I'm using Toolset forms and am trying to use a User registration form checkbox to subscribe. My PHP is dangerous, but I gave it a shot. Am I close? Suggestions?
add_action('cred_save_data', 'perf_subscribe_action',10,2);
function perf_subscribe_action($post_id, $form_data)
{
if ($form_data['id']==56)
{
if (isset($_POST['Keep me up to date']))
{
$name = get_post_meta($post_id, 'first_name', true);
$email = get_post_meta($post_id, 'email', true);
$sendy_url = 'http://mywebsite.com';
$list = 'MyListID';
$api_key = 'MyAPIkey';
$postdata = http_build_query(
array(
'name' => $name,
'email' => $email,
'list' => $list,
'api_key' => $api_key,
'boolean' => 'true'
)
);
$opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));
$context = stream_context_create($opts);
$result = file_get_contents($sendy_url.'/subscribe', false, $context);
echo $result;
}
}
}
