Add the following code to the theme functions.php file (or use a plugin).

12
34
5
6
7
89
10
11
12
13
14
15
add_filter('quform_post_process_1', function($result, $form) {    if (class_exists('TNP_Subscription')) {
        $email = $form->getValue('quform_1_4'); 
        if (!empty($email)) {
            $subscription = new TNP_Subscription();
            $subscription->data->email = $email;
            $subscription->data->lists = array('2' => 1); 
            NewsletterSubscription::instance()->subscribe2($subscription);
        }
    }
 
    return $result;
}, 10, 2);
add_filter('quform_post_process_1', function($result, $form) {
    if (class_exists('TNP_Subscription')) {
        $email = $form->getValue('quform_1_4');

        if (!empty($email)) {
            $subscription = new TNP_Subscription();
            $subscription->data->email = $email;
            $subscription->data->lists = array('2' => 1);

            NewsletterSubscription::instance()->subscribe2($subscription);
        }
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 3, replace 1_4 with the Email element unique ID
  • On line 8, replace the number 2 with the Newsletter list ID (you can find it in the first column of the table on the Lists page within the Newsletter plugin – the list must be Public). Remove line 8 if you do not want to add the user to a list.

Adding subscriber First name and Last name (from a “Name” element)

In the code above, find this line:

1
NewsletterSubscription::instance()->subscribe2($subscription);
NewsletterSubscription::instance()->subscribe2($subscription);

Above it, add the following code:

12
3
$name = $form->getValue('quform_1_3');$subscription->data->name = $name[2];
$subscription->data->surname = $name[4];
$name = $form->getValue('quform_1_3');
$subscription->data->name = $name[2];
$subscription->data->surname = $name[4];
  • On line 1, replace 1_3 with the Name element unique ID

Adding subscriber First name and Last name (from two “Text” elements)

In the code above, find this line:

1
NewsletterSubscription::instance()->subscribe2($subscription);
NewsletterSubscription::instance()->subscribe2($subscription);

Above it, add the following code:

12
$subscription->data->name = $form->getValue('quform_1_5');$subscription->data->surname = $form->getValue('quform_1_6');
$subscription->data->name = $form->getValue('quform_1_5');
$subscription->data->surname = $form->getValue('quform_1_6');
  • On line 1, replace 1_5 with the First name Text element unique ID
  • On line 2, replace 1_6 with the Last name Text element unique ID

Adding a confirmation checkbox

Add a Checkbox field to the form with one option. If you want the checkbox to be on one line, set the Label option to be empty in the field settings (you can enter a label on the Labels tab at the Admin label option if you need it). The user will only be added to the mailing list when the checkbox is checked.

1
2345
6
7
8
9
10
11
12
13
14
15
16
17
18
19
add_filter('quform_post_process_1', function($result, $form) {
    if (empty($form->getValue('quform_1_7'))) {        return $result;    } 
    if (class_exists('TNP_Subscription')) {
        $email = $form->getValue('quform_1_4');
 
        if (!empty($email)) {
            $subscription = new TNP_Subscription();
            $subscription->data->email = $email;
            $subscription->data->lists = array('2' => 1);
 
            NewsletterSubscription::instance()->subscribe2($subscription);
        }
    }
 
    return $result;
}, 10, 2);
add_filter('quform_post_process_1', function($result, $form) {
    if (empty($form->getValue('quform_1_7'))) {
        return $result;
    }

    if (class_exists('TNP_Subscription')) {
        $email = $form->getValue('quform_1_4');

        if (!empty($email)) {
            $subscription = new TNP_Subscription();
            $subscription->data->email = $email;
            $subscription->data->lists = array('2' => 1);

            NewsletterSubscription::instance()->subscribe2($subscription);
        }
    }

    return $result;
}, 10, 2);
  • Add the highlighted lines 2, 3 and 4 to the existing code
  • On line 2, replace 1_7 with the Checkbox element unique ID
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy