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
16
add_filter('quform_post_process_1', function($result, $form) {    if (class_exists('TNP')) {
        $email = $form->getValue('quform_1_4'); 
        if (!empty($email)) {
            $params = array(
                'email' => $email,
                'lists' => array(2),            );
 
            TNP::subscribe($params);
        }
    }
 
    return $result;
}, 10, 2);
add_filter('quform_post_process_1', function($result, $form) {
    if (class_exists('TNP')) {
        $email = $form->getValue('quform_1_4');

        if (!empty($email)) {
            $params = array(
                'email' => $email,
                'lists' => array(2),
            );

            TNP::subscribe($params);
        }
    }

    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 part:

1
2
3
4
$params = array(
    'email' => $email,
    'lists' => array(2),
);
$params = array(
    'email' => $email,
    'lists' => array(2),
);

And replace it with this:

12
3
4
5
6
7
$name = $form->getValue('quform_1_3');$params = array(
    'email' => $email,
    'lists' => array(2),
    'name' => $name[2],
    'surname' => $name[4],
);
$name = $form->getValue('quform_1_3');
$params = array(
    'email' => $email,
    'lists' => array(2),
    'name' => $name[2],
    '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 part:

1
2
3
4
$params = array(
    'email' => $email,
    'lists' => array(2),
);
$params = array(
    'email' => $email,
    'lists' => array(2),
);

And replace it with this:

1
2
3
456
$params = array(
    'email' => $email,
    'lists' => array(2),
    'name' => $form->getValue('quform_1_5'),    'surname' => $form->getValue('quform_1_6'),);
$params = array(
    'email' => $email,
    'lists' => array(2),
    'name' => $form->getValue('quform_1_5'),
    'surname' => $form->getValue('quform_1_6'),
);
  • On line 4, replace 1_5 with the First name Text element unique ID
  • On line 5, 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
20
add_filter('quform_post_process_1', function($result, $form) {
    if (empty($form->getValue('quform_1_7'))) {        return $result;    } 
    if (class_exists('TNP')) {
        $email = $form->getValue('quform_1_4');
 
        if (!empty($email)) {
            $params = array(
                'email' => $email,
                'lists' => array(2),
            );
 
            TNP::subscribe($params);
        }
    }
 
    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')) {
        $email = $form->getValue('quform_1_4');

        if (!empty($email)) {
            $params = array(
                'email' => $email,
                'lists' => array(2),
            );

            TNP::subscribe($params);
        }
    }

    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. © 2020 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy