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!

Comments

paulbeaney’s picture

Hi SchwebDesign,

I'm afraid what you're doing isn't possible for the moment, despite your inventiveness! Doing a form_alter() would be a possibility (as long as you add a $form['#submit'] override too) if - and it's a big if - the subscriptions for logged-in users were handled using a form. As it is, they are not; they use path-based menu callbacks, so that makes this option a no-go.

In any case, a more logical way to handle this kind of scenario would be to implement the Rules API with the PHPlist module, but as I'm running hard just to stand still at the moment, I couldn't say when this might be a possibility.

Sorry not to have more positive news!

Regards,

- Paul

SchwebDesign’s picture

Category: support » feature

Thanks for your honest and thorough answer. I have changed this thread to a feature request. If you ever have any free time for development of this or any news regarding this feature, please let us know! Thanks for all the work you've done on this module thus far.

paulbeaney’s picture

Hi,

Ok, had a bit of time and made a LOT of changes to the module. The DEV release will be going up shortly and will soon turn into a 6.1 release once a few people confirm that it works ok. The changes will then be ported to the D& version.

In the latest version, the My Newsletters page now uses standard Drupal checkboxes rather than links. This means that the form can probably be re-used by other modules:

Form: phplist_user_newsletters()
Submit callback: phplist_user_newsletters_submit()

Regards,

- Paul

gogowitsch’s picture

For Drupal 8 and newer, you can use the Webform phpList module. It adds a handler for sending webform submissions to a self-hosted phpList installation.