Skip Navigation

[Resolved] Execute POST URL for a newsletter list via checkbox on User Registration form.

This support ticket is created 4 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 3 voices.

Last updated by Luo Yang 4 years, 1 month ago.

Assisted by: Luo Yang.

Author
Posts
#1519957

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]

#1520283
generic-field.JPG

Hello,

I assume the checkbox field "Keep me up to date" is created by Toolset Forms generic field shortcode [cred_generic_field]:
https://toolset.com/documentation/user-guides/front-end-forms/cred-shortcodes/#cred_generic_field

I suggest you try these:
Edit the user form(ID: 56), find and edit the generic field "Keep me up to date":
- in option "Field slug", replace the space with charactor "_", for example: Keep_me_up_to_date
- in option "Default field value", fill value: 1
See screenshot generic-field.JPG

If you are using classic edit, above shortcode should be this:

[cred_generic_field type='checkbox' field='Keep_me_up_to_date']
{
"required":0,
"default":"1"
}
[/cred_generic_field]

Then in your PHP codes, you can capature the user's submits, like this:

if (isset($_POST['Keep_me_up_to_date']) && $_POST['Keep_me_up_to_date'] == 1)
...
#1521389
output.png

Then the output looks like this:

#1525175

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Luo is on holiday today. He will get in touch with you tomorrow as soon as you will back to work.

#1526247
checkbox3.JPG

In your case, you just need to change the generic checkbox field slug as: Keep me up to date.

For example:

[cred_generic_field type='checkbox' field='Keep me up to date']
{
"required":0,
"default":"1"
}
[/cred_generic_field]

See screenshot

Then use PHP post variable "Keep_me_up_to_date" like this:

if (isset($_POST['Keep_me_up_to_date']) && $_POST['Keep_me_up_to_date'] == 1)
...
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.