Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Adding mail subscribers to MailPoet list using Formidable form WordPress

I currently use Formidable to host contests on my website, and I use MailPoet to send newsletters. Right now I am downloading/uploading subscribers to MailPoet lists at the end of each contest, but I would like something less labour intensive. (The contest form includes permission to add to my mailing list -- I'm not a spammer!)

MailPoet has provided the following code to make this work:

function processMyForm(){

//you could make some validation even though validation
//is also processed in our function
$my_email_variable = $_POST['my_email_variable'] ;
$my_list_id1 = $_POST['my_list_id1'] ;
$my_list_id2 = $_POST['my_list_id2'] ;

//in this array firstname and lastname are optional
$user_data = array(
'email' => $my_email_variable,
'firstname' => $firstname,
'lastname' => $lastname);

$data_subscriber = array(
'user' => $user_data,
'user_list' => array('list_ids' => array($my_list_id1,$my_list_id2))
);

$helper_user = WYSIJA::get('user','helper');
$helper_user->addSubscriber($data_subscriber);
//this function will add the subscriber to mailpoet

//if double optin is on it will send a confirmation email
//to the subscriber

//if double optin is off and you have an active automatic
//newsletter then it will send the automatic newsletter to the subscriber
}

//initialize this function only when your subscription form data has been posted
add_action('init','processMyForm') ;


I need a little help finding the right variables from Formidable to include in this code. If you are familiar with Formidable, and are able to assist, I would appreciate it.

If what I'm trying to do won't work with multiple forms (ie. I can't map to a specific list from any form without creating a variable for each), I would be glad to know that as well.

Answers (2)

2016-05-03

Hariprasad Vijayan answers:

Hello,


$my_email_variable = $_POST['my_email_variable'] ;
$my_list_id1 = $_POST['my_list_id1'] ;
$my_list_id2 = $_POST['my_list_id2'] ;

//in this array firstname and lastname are optional
$user_data = array(
'email' => $my_email_variable,
'firstname' => $firstname,
'lastname' => $lastname);

These are the section you need to modify based on your Formidable form elements.

<blockquote>$my_email_variable, $firstname and $lastname</blockquote>
Need to get values for these variable from Formidable form.

You can ignore $my_list_id1 and $my_list_id2 variables if you don't have an option for the user to pick subscriber list.
And you can get list id from yoursite.com/wp-admin/admin.php?page=wysija_subscribers&action=lists
You can manually add list ids here
<blockquote>array('list_ids' => array($my_list_id1,$my_list_id2))</blockquote>
then it would be like
<blockquote>array('list_ids' => array(1,2))</blockquote>

Can you show the url where the form displayed to get the variable names?

Regards,
Hariprasad


tristadevries comments:

This is one of the places the form exists, but we create a new form for each contest. The post expires and then we create a new form and post for the next one. This exact form is deleted and never reused.

That's why I'm not sure if this is possible.

http://thetfs.ca/2016/04/15/win-two-tickets-tower-hot-docs-2016/


Hariprasad Vijayan comments:

Okay. Can you tell me about list ids? Are you creating separate list ids for each form?


tristadevries comments:

No. One single list, multiple forms.

The list ID from MailPoet appears to be 6. Is this what you're looking for?


Hariprasad Vijayan comments:

This method won't work in this situation, form element will change each time you create new form.

You can try the plugin that Bob suggested.

2016-05-03

Bob answers:

Have you checked this?
[[LINK href="http://tribulant.com/extensions/view/16/formidable-subscribers"]]http://tribulant.com/extensions/view/16/formidable-subscribers[[/LINK]]

Not only above code require modifications you also need settings to be done.

[[LINK href="http://broadstreetnetwork.com/labs/formidable-pro/formidable-pro-add-mailpoet-subscriber-using-formidable-pro/"]]http://broadstreetnetwork.com/labs/formidable-pro/formidable-pro-add-mailpoet-subscriber-using-formidable-pro/[[/LINK]]

Another way is to use formidable action hook
add_action('frm_after_create_entry', 'yourfunctionname', 30, 2);


Bob comments:

please also checkout this one too
[[LINK href="http://extend.bt4.me/downloads/formidable-mailpoet/"]]http://extend.bt4.me/downloads/formidable-mailpoet/[[/LINK]]


tristadevries comments:

Oh heck, yes. If Rob wrote that, I can definitely use it. That guy taught me most of what I know about web design, so... Thanks, Bob! Super useful!


Bob comments:

:) you are welcome!


Bob comments:

Please close this question if you issue is solved.