Forums

Set up subscribe to email list

pgrgrl 17 Mar, 2015
I think it might be possible to set this up, but I am not sure how. I have only done simple forms in the past. But this would save me a lot of time if it could happen automagically ๐Ÿ™‚ Up to now I have been subscribing each one manually when I receive their membership form email.

I have people signing up for membership from across the state. It is divided up into 9 Regional areas depending on what county they live in. There are 9 corresponding email lists.

So when they choose "my county" it will be programmed to input the "region #" based on their county choice and then subscribe their email address to subscribe-region#@domain.org (the mailing list is on a different domain than the website that the forms are on).

Is this possible, and if so, what elements do I use to do that?
GreyHead 18 Mar, 2015
Hi pgrgrl,

This doesn't sound too difficult.

Use a Custom Code action in the On Submit event to 'look up' the region # and add that to the info sent to the mailing list. You can probably send all that using the cURL action.

Bob
pgrgrl 19 Mar, 2015
Thanks, Bob. Off to do my homework to try to figure that out. I'm excited because yesterday I figured out conditional show/hide containers. I saved the hardest form for last. I will be really excited when I get this working.
pgrgrl 19 Mar, 2015
I used Events on the "County" field to Set Options on the "Region" field. The Region field will be hidden from the user so they can't change it.

Now, I need Custom Code with some php that says "if Region 1 then take this user's email address and subscribe it to Region 1 email list" for all 9 Regions? And the curl will list the 9 different email lists?
GreyHead 20 Mar, 2015
Hi pgrgrl,

How does the 'subscription' bit work? I cant; make that out form the posts here.

Bob
pgrgrl 20 Mar, 2015
I think I thought of an easier way to do it.

Set a hidden field to populate with the email subscribe address based on their county. Then use Dynamic To and Dynamic from on email to send the form with a blank template.

listname1-join@domain.com
listname2-join etc.

This should work? I will try it.
GreyHead 20 Mar, 2015
Hi pgrgrl,

I still don't see how the subscribe bit works.

I don't recommend putting email addresses into hidden inputs - they are publicly visible to scraper bots and may be used by spammers.

You can add them in the On Submit event without needing the hidden inputs.

Bob
pgrgrl 20 Mar, 2015
The mailing list is a Mailman GNU list. You can subscribe to it by sending an email to the listname-join@domain from the email address you want to subscribe to it with. So if I put users email address as the Dynamic From, and put the list email address as the Dynamic To, then this should subscribe them to the list. The list then sends the person an email that says please confirm your subscription, and they have to reply to that in order to be added.

I don't know how to write code, so I don't know how to set it up On Submit.
GreyHead 20 Mar, 2015
Hi pgrgrl,

Please see this FAQ fro a way to handle email addresses from the On Submit event.

Bob
pgrgrl 20 Mar, 2015
Okay, I have gone through and set up field so that the email addresses are not on the form using em1, em2, em3 etc. And added the custom code according to the FAQ.
em1=MailingList1
em2=MailingList2
etc.

In the custom code
em1=mailinglist1-join@example.com
em2=mailinglist2-join@example.com
etc.

When I fill out the form, any option that is chosen is sending to em1 Mailing List 1. It needs to send to whichever list is chosen. The code here in the FAQ says "set a default recipient." How to change it so it sends to the list chosen, not em1 by default?

<?php
// set a default recipient
$recipient = 'em1';
if ( isset($form->data['recipients']) && $form->data['recipients'] ) {
  $recipient = $form->data['recipients'];
}
$emails = array (
  'em1' => 'bob@example.com',
  'em2' => 'info@example.net',
  'em3' => 'admin@example.com' );
$form->data['email_to_use'] = $emails[$recipient];
?>
GreyHead 21 Mar, 2015
Hi pgrgrl,

It only sends to em1 when there is nothing selected in the 'recipients' drop-down. It sounds as though your drop-down may have a different name?

Bob
pgrgrl 21 Mar, 2015
Yes, it had a different name. However, when I changed the name of the dropdown to "recipients" it still only sends to em1. Though the correct choice is showing on the form side. I deleted the dropdown and made a new one and still the same result.

So to review, I have

dropdown box 'county' which by choosing their county, the event Set Options on 'recipients' sets them to em1, em2, em3 etc, and this is showing it works properly on the front end. But the emails are only sending to em1 no matter what recipient is chosen.

This is my custom code:

<?php
// set a default recipient
$recipient = 'em1';
if ( isset($form->data['recipients']) && $form->data['recipients'] ) {
  $recipient = $form->data['recipients'];
}
$emails = array (
  'em1' => 'list1-join@example.com',
  'em2' => 'list2-join@example.com',
  'em3' => 'list3-join@example.com',
  'em4' => 'list4-join@example.com',
  'em5' => 'list5-join@example.com',
  'em6' => 'list6-join@example.com',
  'em7' => 'list7-join@example.com',
  'em8' => 'list8-join@example.com',
  'em9' => 'list9-join@example.com' );
$form->data['email_to_use'] = $emails[$recipient];
?>

I have an email action after the custom code On Submit which says email_to_use in the Dynamic To field and a regular subject called Subscribe and regular from name Subscriber.

The order of my On Submit events Is:

DB Save
DB Read
Email (this sends regular email of the form details to me)
Custom Code
Email (this sends the email to subscribe to the email list)
Display Message

I also need to add anti-spam but I wanted to be sure all this works before doing that. I was getting Honeypot error when I first tried this so I removed it for now.
GreyHead 21 Mar, 2015
Hi pgrgrl,

One more test please. Drag a Debugger action into the On Submit event, then submit the form and post the debug - including the 'dummy emails' results here.
Bob
pgrgrl 21 Mar, 2015
Okay, I see one odd thing here. In the first set of Arrays, it shows what I filled out on the form for this test with choice of Albany for county (should go to em5). Under that where it says [Data 4] it is showing what I had filled out on a previous test (Fulton county should go to em4). 'dropdown8' is the county. 'recipients' used to be called 'dropdown19' but then I renamed it, then when it did not work I deleted it and made a new 'recipients'. Odd how it is remembering 'dropdown19' when it doesn't exist anymore.

Data Array

Array
(
    [option] => com_chronoforms5
    [chronoform] => NewMemj3
    [event] => submit
    [text2] => My name
    [text3] => My address
    [text4] => 
    [text5] => My city
    [text6] => My state
    [text7] => 00000
    [dropdown8] => Albany
    [recipients] => 
    [text9] => 5555555555
    [text10] => myemailaddy@gmail.com
    [text11] => myemailaddy@gmail.com
    [text12] => 
    [textarea16] => 
    [button15] => Submit
    [id] => 10
    [Data4] => Array
        (
            [id] => 1
            [uniq_id] => 2a9f4ee4f0fa30b6e0e1e0464cf8f06e80a08058
            [user_id] => 0
            [created] => 2015-03-21 12:17:37
            [modified] => 
            [text2] => pgrgrl
            [text3] => addy
            [text4] => 
            [text5] => city
            [text6] => state
            [text7] => 11111
            [dropdown8] => Fulton
            [dropdown19] => 
            [text9] => 5555555555
            [text10] => pgrgrl@mydomain.com
            [text11] => pgrgrl@mydomain.com
            [text12] => 
            [textarea16] => 
            [button15] => Submit
        )

    [ip_address] => 00.00.00.00
    [email_to_use] => list1-join@example.com
)

Array
(
)

Errors

Array
(
)

Debug Info

Array
(
    [3] => Array
        (
            [DB Save] => Array
                (
                    [Queries] => Array
                        (
                            [0] => INSERT INTO `jos_chronoengine_chronoforms_datatable_NewMemj3` (`text2`, `text3`, `text4`, `text5`, `text6`, `text7`, `dropdown8`, `text9`, `text10`, `text11`, `text12`, `textarea16`, `button15`, `user_id`, `uniq_id`, `created`) values ('My name', 'My address', '', 'My city', 'My state', '00000', 'Albany', '5555555555', 'myemailaddy@gmail.com', 'myemailaddy@gmail.com', '', '', 'Submit', '0', 'c2fb4a12dbfb92bc947e44092c6d37cb70bc5e6f', '2015-03-21 14:44:03');
                        )

                )

        )

    [4] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data4`.`id` AS `Data4.id`, `Data4`.`uniq_id` AS `Data4.uniq_id`, `Data4`.`user_id` AS `Data4.user_id`, `Data4`.`created` AS `Data4.created`, `Data4`.`modified` AS `Data4.modified`, `Data4`.`text2` AS `Data4.text2`, `Data4`.`text3` AS `Data4.text3`, `Data4`.`text4` AS `Data4.text4`, `Data4`.`text5` AS `Data4.text5`, `Data4`.`text6` AS `Data4.text6`, `Data4`.`text7` AS `Data4.text7`, `Data4`.`dropdown8` AS `Data4.dropdown8`, `Data4`.`dropdown19` AS `Data4.dropdown19`, `Data4`.`text9` AS `Data4.text9`, `Data4`.`text10` AS `Data4.text10`, `Data4`.`text11` AS `Data4.text11`, `Data4`.`text12` AS `Data4.text12`, `Data4`.`textarea16` AS `Data4.textarea16`, `Data4`.`button15` AS `Data4.button15` FROM `jos_chronoengine_chronoforms_datatable_NewMemj3` AS `Data4`
                        )

                )

        )

    [5] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:myemailaddy@gmail.com
                    [2] => Subject:Membership Form
                    [3] => From name:My Website
                    [4] => From email:webemail@example.com
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Body:
<table>
<tr><td></td><td></td></tr>
<tr><td>Full Name</td><td>My name</td></tr>
<tr><td>Address Line 1</td><td>My address</td></tr>
<tr><td>Address Line 2</td><td></td></tr>
<tr><td>City</td><td>My city</td></tr>
<tr><td>State</td><td>My state</td></tr>
<tr><td>Zip Code</td><td>00000</td></tr>
<tr><td>County</td><td>Albany</td></tr>
<tr><td>recipients</td><td></td></tr>
<tr><td>Phone</td><td>5555555555</td></tr>
<tr><td>Email Address</td><td>myemailaddy@gmail.com</td></tr>
<tr><td>Email Address (Confirm)</td><td>myemailaddy@gmail.com</td></tr>
<tr><td>How did you hear about us?</td><td></td></tr>
<tr><td>Comments?</td><td></td></tr>
<tr><td></td><td></td></tr>
</table><br /><br />IP: 00.00.00.00
                )

        )

    [10] => Array
        (
            [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:list1-join@example.com
                    [2] => Subject:Subscribe
                    [3] => From name:Subscriber
                    [4] => From email:myemailaddy@gmail.com
                    [5] => CC:
                    [6] => BCC:
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Body:
.
                )

        )

)
pgrgrl 21 Mar, 2015
The Fulton county tests were the first tests made after creating the database table, so apparently it is reading from that?
GreyHead 21 Mar, 2015
Hi pgrgrl,

So the code is working correctly - there is no value set for recipients and it is using the default value.

The question then is why there is no value for recipients?? ChronoForms usually has no memory (unless you have saved values to the User session). Do you have site caching on? That might delay the HTML from updating.

Bob
pgrgrl 21 Mar, 2015
Cache Off
Cache Handler File
Cache Time 30
Session Lifetime 15
Session Handler Database
pgrgrl 21 Mar, 2015
I created the table yesterday.

On the 'recipients' element I do not have anything entered in options value=title, does that need to be filled in?
pgrgrl 21 Mar, 2015
On DB Read, it says Enable Model ID Yes and Model ID Data4 (I don't remember setting this up this way, is that a default value?) Data4 seems to be what the Debug is showing where the old data was showing. I disabled DB Read, no change on the behavior of the email in next test.

I added values to 'recipient' field em1=em1 etc. No change in behavior.

I made 'recipient' a required field, and then on the form it says "this field is required" even though em5 is showing in the box and it will not allow the form to submit.
pgrgrl 21 Mar, 2015
Must be a relationship between the County field which events populate the recipient field.

The event reads:

= Albany Set Options recipients =em5=em5

It populates the form field with em5 but no real value.
GreyHead 22 Mar, 2015
Hi pgrgrl,

The Help text says "In Multiline format, value=Title" and there is an example in the Options box like this:
0=No
1=Yes

I guess that you need something like
em1=This region
em2=That region
em3=Some other region

Bob
pgrgrl 23 Mar, 2015
I think the problem is where I pull the values from the county dropdown to recipients dropdown, on the events tab I only have:
= Countyname Set Options recipients =em#
I have no corresponding != values added in events.

Since there are over 60 counties, it is rather a mess. So now I am looking at pulling the list dynamically. But I don't know how to set up the data table.

Can I create a table from CF by making a new form and saving it? If so, how do I set up the form so that the correct fields and values are created in the table?

I have looked at some of the tutorials but I am sort of lost. I have a list of county=em# and I looked at creating an array and created a list of "County" => "em#", to put in some code, but I don't know where to put the code or what other code goes with an array list.
pgrgrl 23 Mar, 2015
Summarizing for myself because I have gotten very confused trying different things.

User selects their county in dropdown8 box (they choose one of over 60 choices).

I need the recipients box to be populated depending on their choice, the value on recipients has to be:
em1
em2
em3
em4
...... through em9

Adding individual events for each county on dropdown8 to populate recipients did not add values. Form was returning no values in recipients. And was difficult because of the number of options.

So I need either Ajax, or use Dynamic Data from another table to make this work?

I created new form called county_regions with a field called county_region which is populated with
em1 = this county
em2 = that county (for all 60+ counties).

Now I do not know how to make dropdown8 choices populate to recipients based on that data.

Or do I need an additional field, first they choose their county, then that populates a field with their Region #
this county = this region
that county = that region

Then recipients is populated from Region # field?
em1=Region1

I have been reading this FAQ: http://www.chronoengine.com/faqs/58-cfv4/cfv4-elements-and-html/2647-how-do-i-build-a-select-drop-down-radio-button-or-checkbox-group.html

It seems like this part is what I would want:
Simple double drop-down
" In the simplest use you can ignore the two AJAX boxes and enter your lists of options directly into the Extra Options Extension box. "
What is the "Extra Options Extension box"? Is this the same as the "extra params" box?

These different methods are confusing me.
pgrgrl 24 Mar, 2015
It works now!!!! Not sure what I had wrong before.

County field
General Options
County1=County1
County2=County2
etc


County field Events
=  County1    Set Options   recipients  em1=em1
= County2    Set Options   recipients  em2=em2


Recipients field has only
Field name: recipients
Field ID: recipients
Field Label: recipients


Custom Code in the On Submit in setup
<?php
// set a default recipient
$recipient = 'em1';
if ( isset($form->data['recipients']) && $form->data['recipients'] ) {
  $recipient = $form->data['recipients'];
}
$emails = array (
  'em1' => 'list1-join@example.com',
  'em2' => 'list2-join@example.com',
  'em3' => 'list3-join@example.com',
  'em4' => 'list4-join@example.com',
  'em5' => 'list5-join@example.com',
  'em6' => 'list6-join@example.com',
  'em7' => 'list7-join@example.com',
  'em8' => 'list8-join@example.com',
  'em9' => 'list9-join@example.com' );
$form->data['email_to_use'] = $emails[$recipient];
?>


Email action On Submit in Setup
Dynamic To:  email_to_use
Basic Subject:  Subscribe
Basic From:  Subscriber


I'm buying the beer now.
GreyHead 24 Mar, 2015
Answer
Hi pgrgrl,

The values in the countries drop-down doesn't have to be em1, em2, - it can be anything that is useful. For countries it might be good to use the ISO country codes for instance:
AF=Afghanistan
AX=ร…land Islands
AL=Albania
. . .
ZW=Zimbabwe

You then need to use the same values to look up the regions after the form is submitted.

Equally the drop-down doesn't need to be called 'recipients', if you call it 'countries' then the selected value will be in $form->data['countries']

Bob
pgrgrl 24 Mar, 2015
Since I'm hiding that field from the user anyway, it doesn't matter to me what it is called or how it displays. As long as the email sends to the right list, that is the important thing. This is going to save me time since I was doing these email subscriptions manually. I feel like a huge weight is gone!

Many, many thanks!!!
GreyHead 25 Mar, 2015
Hi pgrgrl,

Thank you - good to hear that you got it working in the end.

Bob

PS Looks like my last post on the countries list was out of order - I must remember to refresh the browser before replying.
This topic is locked and no more replies can be posted.