Hello. I have custom hook for Formit to submit the name and email to the Campaign Monitor API.
If I add the snippet on it's own to a MODx resource it works okay. It's I use it as a hook with manually entered name & email Formit fire the hook okay. I've now tried to add the placeholders but it doesn't work. I'm not a PHP coder so treat me like a numb nut. If someone could update the code I would really appreciate it!... I'm sure many others will find it useful as well!
<?php
require_once 'core/components/campaignmonitor/csrest_subscribers.php';
$wrap = new CS_REST_Subscribers('xxx', 'xxx');
$result = $wrap->add(array(
'EmailAddress' => '[[+email]]', <--- This works if manually enter an email address
'Name' => '[[+name]]', <--- This works if manually enter a name
'CustomFields' => array(
array(
'Key' => 'Field Key',
'Value' => 'Field Value'
)
),
'Resubscribe' => true
));
return true;
Many thanks
-
MODX Staff
- 2,502 Posts
You can't call formit placeholders in a snippet like this. You have to use the variable:
If your field name in your form is labeled as [[+fi.email]] (provided you were using the default FormIt call) you would create a variable called $email
$email = $hook->getValue('email');
and use in your array.
$result = $wrap->add(array(
'EmailAddress' => "$email",
'Name' => '$name',
'CustomFields' => array(
array(
'Key' => 'Field Key',
'Value' => 'Field Value'
)
),
'Resubscribe' => true
));
return true;
or something very similar
Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup
magician.
Blog ✦
Twitter ✦
LinkedIn ✦
GitHub
Perfect, That's exactly what I needed... Thank you very much for your help.
-
MODX Staff
- 2,502 Posts
No problem. Have fun and do well.
-J
Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup
magician.
Blog ✦
Twitter ✦
LinkedIn ✦
GitHub