add subscribe field to webform

Created on 5 January 2011, almost 14 years ago
Updated 2 September 2024, 3 months ago

Hello, thanks for your help with this module, it's truly a great one. How can I add the newsletter subscribe form to an arbitrary form created using the Webform module?

For example, a website has a "Catalog Request" form created with the Webform module. I'd like for this form to automatically subscribe whatever email address and name are entered by the user to the chosen list, just the same as the user registration form does.

Here are the two methods i have tried thus far and their results:

Method 1

Editing the components of the catalog request Webform itself, i added a new webform "markup" component with the following info:

Label:

Newsletter Subscribe

Field Key:

newsletter_subscribe

value:

<fieldset><legend>Mailing lists</legend>Subscribe to the newsletter to stay up-to-date with Amish Hand Crafted sales, updates, and other news!<div class="form-item">
 <label>Subscribe me to: </label>
 <div class="form-checkboxes"><div class="form-item" id="edit-phplist-subscribe-lists-2-wrapper">
 <label class="option" for="edit-phplist-subscribe-lists-2"><input type="checkbox" name="phplist_subscribe_lists[2]" id="edit-phplist-subscribe-lists-2" value="2"  checked="checked"  onclick="if(this.value==2)this.checked=true" class="form-checkbox" /> <b>AmishHandCrafted.com Users' Newsletter</b> <blockquote><i>You'll be the first to be updated on Amish Hand Crafted sales, updates, and other news!  We promise we won't email you too often and you can unsubscribe at any time.</i></blockquote> (Required)</label>
</div>
</div>
</div>
</fieldset>

Input Format:

PHP code

Results:

Nothing. Form submission worked as always but no email added as a user to the phplist list.

Method 2

Editing phplist.module, i inserted the following code below line 1383. Essentially just tacked it on to the if statements within:

function phplist_form_alter(&$form, &$form_state, $form_id) {
  elseif ($form_id == 'webform_client_form_75') {
    // Ensure auto-subscribe happens if required
      $lists = _phplist_get_lists($user);

      $form['phplist_subscribe_lists'] = array(
        '#type' => 'value',
        '#value' => $lists[0]->lid,
      );
  }

Results:

Nothing. This didn't change the webform at all.

Any help, advice, or even comments would be greatly appreciated! I'm sure this is "easy" to do and i'm likely just having a brain-fart, but i'm not quite able to get it just yet. Thanks!

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States SchwebDesign

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024