• PHP scripts with RSForm and AcyMailing v6.x

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);

}

Great thanks a lot.

I will test, as soon as possible I will give feedback.

Thank you very much.

I am in doubt about this field, where I will search, I confess that I cannot understand:

// check if user wants to subscribe
if (empty ($ postData ['subscribeme'])) return; {// change value between brackets and single quotes to your own fieldname

I have the Name field, email and a custom field, I made the changes, but this field 'Subscribeme'.

    pantaleaogc It is a checkbox field with the name 'subscribeme' and 1 item (in my case 'inschrijven nieuwsbrief'

    So people can opt-in to the newsletter..

    It worked, getting it.

    One detail, create a custom phone type field.

    But the information is going to the country code.

    It will be like we do to maintain a unique country code and send the phone number to the main field.

    $ customFields = [];
    $ customFields ['3'] = strip_tags ($ postData ['mobile']); // change value between brackets and single quotes to your own fieldname current field value will always be updated with form value

    I remember that in Acymailing 5, we had something like this:

    $ myUser-> country = strip_tags ($ postData ['CustomFildes']); // Please replace name_field by your own field name (the name of the field "name").

    Thanks in advance...

    Hi,

    The custom phone field has two parts:

    customField[field_number][code] 
    customField[field_number][phone] 
    

    So you would either need two corresponding fields in you form or to split up the single phone field in two parts.

    In case you only store the complete number in the [phone] part of the field Acymailing will try to add the correct country code. That might end you up in having a phone number in Acyailing with a double country code.

    a month later

    Hello, I'm confused looking at this post. which code that would work with RSforms?

    6 months later

    This is as clear as muddy river after a storm. Seriously can we not get a simple and clean integration tool like RS forms does to Mailchimp.....is that so hard to give a good clean experience to your customers?

    I have tried to follow what is being said above but it is not clean cut.
    I have a subscription form that is called Subscription form. It has three fields seen in the attachment

    I have created the following PHP script. When I test it from the front end it says successful however I do not see any record created in the backend on Acymailing.

    // get form data
    $postData = $_REQUEST['Subscription Form'];

    // check if user wants to subscribe
    if(empty($postData['Submit'])) 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['Email'])); // 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['Email']); // change value between brackets and single quotes to your email address fieldname
    $myUser->name = strip_tags($postData['First Name']); // change value between brackets and single quotes to your name of the person fieldname current field value will always be updated with form value
    $myUser->name = strip_tags($postData['Last Name']); // 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['2'] = strip_tags($postData['Email']); // change value between brackets and single quotes to your own fieldname current field value will always be updated with form value
    $customFields['1'] = strip_tags($postData['First Name']); // change value between brackets and single quotes to your own fieldname current field value will always be updated with form value
    $customFields['3'] = strip_tags($postData['Last Name']); // 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 = [3]; // change value between brackets to your id of the acymailing list use comma for multiple lists
    $userClass->subscribe($myUser->id, $listToSubscribe);

    }

    Here is a view of my Acymail custom fields


    What is wrong here?
    And can you please update your documentation to include version 6 requirements.

    KiwiBA

    Hi,

    I noticed you also raised a support ticket for this, so let's continue from there. Please be so kind to post your questions only once,either in a ticket or on the forum. I have deleted your second post with the same question on the forum. Thank you for undersdtanding.

    4 months later