This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.
This guide will show you how to integrate Quform and the MailPoet Newsletter plugin, by adding subscribers to your mailing list when the form is submitted. The code will be slightly different depending on what fields you want to save, we have added a few different code examples below, choose one that suits your form setup. In each guide you should add the code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).
Saving just an email address
1 2 3 456 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function my_quform_mailpoet_subscribe($form) { if (class_exists('WYSIJA')) { $email = $form->getValue('iphorm_1_1'); $listId = 1; $user_data = array( 'email' => $email ); $data_subscriber = array( 'user' => $user_data, 'user_list' => array('list_ids' => array($listId)) ); $helper_user = WYSIJA::get('user','helper'); $helper_user->addSubscriber($data_subscriber); } } add_action('iphorm_post_process_1', 'my_quform_mailpoet_subscribe'); |
function my_quform_mailpoet_subscribe($form) { if (class_exists('WYSIJA')) { $email = $form->getValue('iphorm_1_1'); $listId = 1; $user_data = array( 'email' => $email ); $data_subscriber = array( 'user' => $user_data, 'user_list' => array('list_ids' => array($listId)) ); $helper_user = WYSIJA::get('user','helper'); $helper_user->addSubscriber($data_subscriber); } } add_action('iphorm_post_process_1', 'my_quform_mailpoet_subscribe');
- On line 4, change
iphorm_1_1
to your Email element unique ID - On line 5, change the number
1
to the ID of the list you want to add the subscriber to, you can find this number in the address bar when editing the list - On line 20, change the number
1
to your form ID
Saving the first name, last name and email address
1 2 3 45678 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | function my_quform_mailpoet_subscribe($form) { if (class_exists('WYSIJA')) { $firstname = $form->getValue('iphorm_1_1'); $lastname = $form->getValue('iphorm_1_2'); $email = $form->getValue('iphorm_1_3'); $listId = 1; $user_data = array( 'email' => $email, 'firstname' => $firstname, 'lastname' => $lastname ); $data_subscriber = array( 'user' => $user_data, 'user_list' => array('list_ids' => array($listId)) ); $helper_user = WYSIJA::get('user','helper'); $helper_user->addSubscriber($data_subscriber); } } add_action('iphorm_post_process_1', 'my_quform_mailpoet_subscribe'); |
function my_quform_mailpoet_subscribe($form) { if (class_exists('WYSIJA')) { $firstname = $form->getValue('iphorm_1_1'); $lastname = $form->getValue('iphorm_1_2'); $email = $form->getValue('iphorm_1_3'); $listId = 1; $user_data = array( 'email' => $email, 'firstname' => $firstname, 'lastname' => $lastname ); $data_subscriber = array( 'user' => $user_data, 'user_list' => array('list_ids' => array($listId)) ); $helper_user = WYSIJA::get('user','helper'); $helper_user->addSubscriber($data_subscriber); } } add_action('iphorm_post_process_1', 'my_quform_mailpoet_subscribe');
- On line 4, change
iphorm_1_1
to your First Name element unique ID - On line 5, change
iphorm_1_2
to your Last Name element unique ID - On line 6, change
iphorm_1_3
to your Email element unique ID - On line 7, change the number
1
to the ID of the list you want to add the subscriber to, you can find this number in the address bar when editing the list - On line 24, change the number
1
to your form ID