• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Adding a checkbox to a form to allow users to subscribe to newsletter (acymailing)

I got that piece of code from RSForms who have an acymailing code snippet that allows forms to have a radio button to select whether they wish to subscribe to a newsletter or not. I knew that wouldn't work, but I just put that in for you to see and to get an idea. I know I can use the code from your previous thread and that'll work, but only when the form is submitted without the radio button option. This is what I am looking for. It would be nice to have an acymailing plugin, just like your mailchimp plugin to work with your forms as you have every plugin except the kitchen sink. I don't really want to use RSForms as Fabrik is far more powerful and better.
 
Last edited:
You haven't answered my question. Are you using those placeholders literally, or are you using your actual element names?

And $postData doesn't exist. Just use a placeholder for that.

-- hugh
 
Sorry Hugh, no I am using my own element names of course. I actually copied this code from another thread I mentioned in this thread. I did also mention that I copied the $postData snippet from an RSForms code that uses acymailing for an option selection such as a checkbox to trigger or not subscription to a newsletter. I just added this piece of code for someone on here to help me integrate something like this in Fabrik. So in a nutshell, the acymailing gets submitted when a user makes a selection, by checking or unchecking a checkbox, which now I think about it, is probably the standard way of doing this.
 
I only added this part of the code snippet to the existing Fabrik/acymailing code:

if(empty($postData['yourtable___newsletter']))return;

You said I should use a placeholder instead, however a placeholder is already present above, so what can I replace $postData with for your form to work. this is what confuses me.
 
Try ...

Code:
if(empty({'yourtable___newsletter'}) {
   return;
}

If that does work, do this ...

Code:
$newletter = '{yourtable___newsletter}';
var_dump($newsletter);exit;
if(empty($newsletter) {
   return;
}

Submit the form. That should dump out whatever the element placeholder is set to. Then adjust the 'if' condition to suit, and remove the var_dump line.

-- hugh
 
Hi Hugh,

I tried everything to get this working, but I think I'm nearly there.

Here is the code I am using in the redirect plugin of the form (these are my actual placeholders):

Code:
$myEmail = '{contact_us___email_address}';
$myName = '{contact_us___full_name}';
$newsletter = '{contact_us___newsletter}';

if (!empty($myEmail)) {
   if (! include_once JPATH_ADMINISTRATOR . '/components/com_acymailing/helpers/helper.php')
   {
      throw new RuntimeException("Acymailing not installed");
      return false;
    }
  
    //Option to allow user to subscribe to newsletter
if (empty($newsletter)) {
   return;
   } 
  
   $myUser = new stdClass();
   $myUser->email = $myEmail;
   $myUser->name = $myName;
  
   //If you require a confirmation but don't want the user to have to confirm his subscription via the API, you can set the confirmed field to 1:
   //$myUser->confirmed = 1;
   $subscriberClass = acymailing_get('class.subscriber');
   $subid = $subscriberClass->save($myUser);

   $newSubscription = array();
   $newList = array();
   $newList['status'] = 1;
   $newSubscription[1] = $newList; // Replace 2 with the ID of the list.

   $subscriberClass->saveSubscription($subid,$newSubscription);
}

The jump URL I am using is:

Code:
index.php?option=com_acymailing&ctrl=sub&task=optin&hiddenlists=1&user[name]={name}&user[email]={email}

I tried both codes you sent, but no joy. I'm also not sure what position to add the code so I tried most areas and still no success.

If I remove the newsletter code, the form automatically gets submitted to the newsletter list, so I think we are nearly there. Just maybe a bit of tweaking to get it just right.

Thanks
 
Last edited:
I finally figured it out. The newsletter value is never really empty. I used a 'print_r' statement on the newsletter code to test the newsletter value and when it is not checked, it throws out a bullet point value.

I then changed the code to the following statement:

Code:
if($newsletter != "Yes"){
    return;
}

As you can see I set the value to 'Yes' when checkbox is checked and now it works well.

Thanks for all your help Hugh.
 
Code:
$newsletter = '{contact_us___newsletter_raw}';

Any element type that has a concept of "value" and "label" (like dropdowns, radios, joins, etc), appending _raw to the name gets you the value. Just the name gets you the label.

-- hugh
 
The append_raw doesn't seem to work. Maybe I should leave it as it as I only have one checkbox with one value at the moment.
Thanks for you all your help. It is much appreciated.
 
Now that it all seems to be working well thanks to you. When the user submits the form and they select (check) the Newsletter checkbox, I'd like to show some information telling the user that they selected newsletter subscription. When the form is submitted, they get a message saying record has been saved, etc. I would like to add to that message telling them they have also subscribed to the newsletter. Is this possible?

Thanks
 
As always Hugh, you're a genius. Thank you very much again. If you were to create the acymailing plugin at some point in the future, I would buy it off you in a heartbeat.
 
Sorry to bother you again. I noticed that when I submit some dummy data, it returns back to the contact us form again, which is fine, however it fills the details with some other dummy data I added before and no matter how many times I submit different data, it keeps filling in the same data I submitted ages ago. What can I do to remove any data from the forms after it has been submitted. I tried different settings on the backend, but I can't get the form to be blank after submission. The only way around this would be to add a successful message in an article and direct it to that article after submission, which I don't really want to do.

Thanks
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top