JjaccsSupport Beginner
- Edited
I have everything working many thanks for that!! What I tested:
- check if person wants to subscribe
- check if person already exists
- when user exists; update
- when user does not exists, create new user
- subscribe to multiple lists
- 1 custom field, in my case a phone number
The exact script that I am using:
// get form data
$postData = $_REQUEST['form'];
// check if user wants to subscribe
if(empty($postData['subscribeme'])) return; { // change value between brackets and single quotes to your own fieldname
include_once(rtrim(JPATH_ADMINISTRATOR, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acym'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php');
$userClass = acym_get('class.user');
$myUser = $userClass->getOneByEmail(strip_tags($postData['e-mail'])); // change value between brackets and single quotes to your email address fieldname
// check if email address already exists
if (empty($myUser)) {
$myUser = new stdClass();
}
$myUser->email = strip_tags($postData['e-mail']); // change value between brackets and single quotes to your email address fieldname
$myUser->name = strip_tags($postData['naam']); // change value between brackets and single quotes to your name of the person fieldname current field value will always be updated with form value
// Custom fields
$customFields = [];
$customFields['4'] = strip_tags($postData['Telefoonnummer']); // change value between brackets and single quotes to your own fieldname current field value will always be updated with form value
$myUser->id = $userClass->save($myUser, $customFields);
$listToSubscribe = [6,8]; // change value between brackets to your id of the acymailing list use comma for multiple lists
$userClass->subscribe($myUser->id, $listToSubscribe);
}