I want users to subscribe to a Sendy List by check box on user registration via POST URL. (following the recommended Sendy API)
Form: hidden link
I started here: https://toolset.com/forums/topic/add-user-to-sendy-list-via-registration-form-checkbox-and-jquery/
I'm not sure if I am using the correct syntax for cred api (cred_save_data) and checkbox field "if (isset($_POST['Keep me up to date']))"
Can you tell me if the toolset related items are correct?
Thanks!
[/php]
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 = 'hidden link';
$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;
}
}
}
[php]