Forums

PHP action / AcyMailling subscribe action in ChronoForms

jj135 01 Dec, 2020
These is our scenario:
We use a chronoforms 6 form to let users register for a website. On this form data like name, e-mail and others are submitted,
After filling out the form the user receives an e-mail with an activation link.
After clicking on the link the form is 'triggered' again and the user activation (Joomla) is done.

Now we want to add some PHP code to when the user activates his/her account using the link. We have the 'user activation' action on the activate 'page' here we want to add some code to also subscribe the user to the AcyMailing newsletter.

To be able to do this we need: The username and e-mail that has been submitted by the user on the registration form (before the activation ink was send). Is this data still available at this point under {data:email) and {data:name} Or maybe in the session? How can we use these values in a PHP custom script to get the newsletter subcription done?

Or do we need to retrieve the user data first at this point to be able to use it in a custom piece of PHP code?

Any suggestions? Thanks!
jj135 02 Dec, 2020
Hi! I added a debugger to the activation page and this shows me what data is available, In the joomla user activation array I see the name and email of the user. Excellent. I should be able to use that to create a acymailing user. Not sure how to access this data using PHP, but I give it a try..

There is one more thing: On the user registration form there is an option to subscribe to the newsletter. And I only want to add a user to the maulinglist when this checkbox is checked. But I do not see the value of this field in the debugger data... So is there a way to know at this point if the user wants the newsletter or not?? So can I access the form filed values at this point somehow?

There is a 'params' variable in the debugger joomla_user_actovation array. This is empty. Maybe there is a way to get some value in there?

Anpother approach migt be to add a URL parameter to the registtration link (&newsletter=1 for example) and try to grab this with PHP ('GET')?
jj135 02 Dec, 2020
I have now added the data from the newsletter field (yes/no) to the activation link as an URL parameter and using 'GET' in PHP I get this value from the URL. So now I know the user want to subscribe to the newsletter. Great. There might be other ways to do it, but for now I think this will work OK.

But as I mentioned before, I used the CF debugger to show me the data that is available to use in PHP after the actoivation link in the mail has been used. This debugger shows me:[blockquote]Array
(
[option] => com_chronoforms6
[cont] => manager
[chronoform] => user-registration
[event] => activate
[code] => 69ade40d-f6ee-4bf4-afde-8627edae2dd2
[a37f6764e9baf05554ea5c8ce0e0ff60] => bd2850a73103efadf511ba2db26df414
[53b2486a068866376a852f1a36bb11c3] => de4eedea6610492d669a74a10ee19b03
[language] => en-GB
[Itemid] =>
[lang] => en-GB
)
Array
(
[joomla_user_activation4] => Array
(
[_success] => User activated successfully.
[var] => Array
(
[id] => 240
[name] => Jip Jonker
[username] => jjonker
[email] => jipjonker@inxpact.nl
[password] =>
[block] => 1
[sendEmail] => 0
[register_date] => 2020-12-02 09:12:32
[lastvisitDate] => 0000-00-00 00:00:00
[activation] => 69ade40d-f6ee-4bf4-afde-8627edae2dd2
[params] =>
[lastResetTime] => 0000-00-00 00:00:00
[resetCount] => 0[br] [otpKey] => [br] [otep] => [br] [requireReset] => 0[br] )[br] )[br])[/blockquote]
But I can't seem to get the name and email from this data using PHP.

Can anyone help me to get the values from the joomla_user_activation4 array, especially the [name] and [email] values? If I can get those I have all the variables I need fo create the newsletter subscription PHP script.
jj135 03 Dec, 2020
Hi! I keep on going ;-) I figured out a way to get the data I see in the debugger in my PHP script.

I created a data builder action in the 'onsucces' of the user activation action.
In the databuilder I created two variables:
Type: Variable -> Name: acyname -> Value: {var:joomla_user_activation4.name}
Type: Variable -> Name: acymail -> Value: {var:joomla_user_activation4.email}

In the PHP script I can now use these values like this:

$this->get("acyname");
$this->get("acymail");

If there are any suggestions to do this better / different, please let me know

So now I have 'name' 'email' and 'subscribe (yes/no fro URL) and I can now build the acymailing 'add-user' script.
jj135 03 Dec, 2020
And the final step is finished and it works! Just for anyone who is interested: I use this PHP script to subscribe the user tot AcyMailing (v6) when the activate their account and have the newsletter option set to 'yes':

<?php
use AcyMailing\Classes\UserClass;
if ($_GET["nl"]=="Yes"){
$myUser=new stdClass();
$myUser->email=$this->get("acymail");
$myUser->name=$this->get("acyname");
$myUser->active=1;
$myUser->confirmed=1;
$customFields=[];
$userClass=new UserClass();
$userClass->sendConf=false;
$userId=$userClass->save($myUser, $customFields);
$subscribe=[1];
$userClass->subscribe($userId, $subscribe);}
?>

As you can see we get the newsletter (yes/no) from the URL we used in the activation link.
When this is set to 'Yes' we add the user to AcyMailing.
We get the email and name values from the variables we created in the databuilder and use this in the Acymailing add user script.
We set the AcyMailing user to 'active' and 'confirmed' because no extra confirmation is needed.
We also don't sen a confirmation e-mail.
In the last lines we subscribe the newly created user to the mailing list in AcyMailing.
You need to login to be able to post a reply.