Below is a new Webform component newsletter_email that allows to create subscription and unsubscription forms like shown in the attached screenshots, to be handled by the Simplenews module.

Based on an idea by Drupal.org user "yraber" posted at http://drupal.org/node/127178#comment-754353, but improved by me. Unlike the original version, this improved version supports:

  • The latest versions of Drupal 6.x, Webform 6.x-2.x and Simplenews 6.x-1.x
  • [ ] User email as default checkbox
  • "Subscription" or "Unsubscription" Action selectable as radio buttons
  • Width field
  • Value of E-Mail field (newsletter_email component) will be mailed when Webform is set to do so
  • E-Mail field is available in the "E-mail from address" Component list (requires patch)

Simply copy the attached .txt file as "newsletter_email.inc" into the Webform module's "components" directory to make the new component available to webforms.

Comments

roball’s picture

StatusFileSize
new7.48 KB

Here is an updated version of "newsletter_email.inc" (Version 2009-07-21) with some bug fixes.

naught101’s picture

subscribe

roball’s picture

Attached is the patch mentioned in my starting post. The attached screenshot shows how the "Webform mail settings" section of the Webform node's [ Configuration ] tab then may look like.

Jackinloadup’s picture

subscribe

roball’s picture

naught101 and jackinloadup, did you try this add-on? The only problem I am currently observing is when viewing a single submission result (at node/NID/submission/SID): The E-Mail field always shows the address of the logged-in user instead of the submitted address. Any clues on how to solve this?

Jackinloadup’s picture

@roball
No i havent yet tested this. I used the previous method (http://drupal.org/node/127178#comment-754353) but havent had a chance to implement your version yet. I will review and comment when i get the chance.

Thanks for the submission.

naught101’s picture

no, I haven't. Been doing some researching, thinking http://drupal.org/project/contact_manager + simplenews might be the way to go for me..

emdalton’s picture

subscribe - I'll try to test this within the next few days.

haggins’s picture

Thank you very much, works like a charm!

botris’s picture

Subscribe

Jackinloadup’s picture

Is it possible to to get this included in Webform?

emdalton’s picture

I tested the patch and it does seem to work. However, it doesn't allow the user to select which newsletter they wish to subscribe to. Could that be added as a form field or exposed somehow? Or would it make more sense to patch simplenews to be able to read a form field and decide which newsletters to send to which subscribers that way?

botris’s picture

The patch works for me.
Right now it's an e-mail field, is there a way to change this to an select field?

In my situation, people leave their contact information, email, adres...
It would great to have an option "Subscribe to our news letter aswell? Yes / No"...

Please advise how to go about.

rukaya’s picture

StatusFileSize
new7.61 KB

I've changed newsletter_email.inc slightly so that it does what emdalton describes. I'll attach it here in case anybody else finds it useful. It should find each newsletter type and allow users to select with checkboxes which ones to sign up to. If more than one's selected it'll sign the user up to each of them.

UNarmed’s picture

Can the values added in the webform be used when i create a newsletter issue.

e.g if i have a field called subscriber name in the web form, can i use something like !subname in the body of the newsletters to personalise them?

gmreed’s picture

This integration between webform and simplenews is a great idea, thanks! I have just been testing the modified newsletter_email.inc in #14 (allowing users to select which newsletters to subscribe to) and am getting the following error:

warning: Invalid argument supplied for foreach() in .../sites/all/modules/webform/webform_components.inc on line 587.

My setup is:

Core 6.13
Webform 6.x-2.9
Simplenews 6.x-1.0

I have applied the patch in #3 and first tested with the newsletter_email.inc file in #1 without encountering any problems.

Any ideas on how to correct would be much appreciated. Thanks.

UNarmed’s picture

How do i get the webform to send the added information to simplenews subscriptions??

Also i am getting the following error it thats perhaps why it is not working for me.

warning: Invalid argument supplied for foreach() in /home/ehbeatco/public_html/marketing_club/sites/all/modules/webform/webform_components.inc on line 587.

Much thanks

tchopshop’s picture

Hello,

I'm getting the same foreach () error on line 587 as #16 and #17 when applying the patch from #14. Please advise...

thanks
Elena

UNarmed’s picture

Looks like all 3 of us are in the same boat =/

Help would be much appreciated.

roball’s picture

Version: 6.x-2.x-dev »
StatusFileSize
new7.57 KB
new3.59 KB

Here are both the "newsletter_email.inc" file and the patch tested with the latest Webform 6.x-3.x and Simplenews 6.x-2.x dev versions.

UNarmed’s picture

Thanks a lot il give this a try and report back.

UNarmed’s picture

Hmmm i have used the exact same module versions as you and i have installed the patches. For some reason the webform dosent send the e-mail address to the simplenews subscriptions section.

wroxbox’s picture

Subscribe

mlncn’s picture

Status: Needs review » Reviewed & tested by the community

Great work Rob!

I think you meant http://drupal.org/files/issues/webform__newsletter_email.patch for the patch (rather than the print module support patch). That one still applies (with an offset of -142)!

If this is not accepted into Webform, is it possible to have webform recognize components stored elsewhere? Perhaps this can go into Simplenews or if absolutely necessary a completely new module.

benjamin, agaric

roball’s picture

StatusFileSize
new819 bytes

Oops - yes Benjamin - I have mixed up two separate issues. The correct patch tested with the latest 6.x-3.x-dev version of Webform is attached to this post.

quicksketch’s picture

It's unlikely that this will be added to Webform. However, a patch to allow other modules to provide components is at #151603: Can I put options in a select field from a database query?, which I plan on adding.

quicksketch’s picture

Status: Reviewed & tested by the community » Postponed

This will not be added to Webform core. The 3.x version now supports a public API that allows any module to provide components. I'd suggest seeing if SimpleNews is interested in including the integration, otherwise I'd suggest creating a new project that includes this code.

See #340241: Provide hook_webform_component_info() to allow 3rd-party components for information about the new hook, and check out the API information: http://drupalcode.org/viewvc/drupal/contributions/modules/webform/webfor...

pcambra’s picture

Status: Postponed » Active

Hi

I've adapted the code provided above in a new module called Webform Simplenews Component (http://drupal.org/project/webform_simplenews) and I'm testing it in my last site. It uses the new Webform 3.x API.

But I've found myself stuck in one last thing, as the newsletter email component I've created is in fact an email, I don't see the way to add it to the email configuration tab of Webform options, I've dug into the webform module code and I've found a couple of things there:

In webform.emails.inc, webform_emails_form there is this code:

  $form['add']['email_component'] = array(
    '#type' => 'select',
    '#options' => _webform_component_options($node->webform['components'], 'email'),
  );

And that function _webform_component_options in webform.module is like this

function _webform_component_options($components, $type) {
  $acceptable_types = $type == 'email' ? array('email', 'select', 'hidden') : array('textfield', 'select', 'hidden');
  $options = array();
  foreach ((array)$components as $cid => $component) {
    if (in_array($component['type'], $acceptable_types)) {
      $options[$cid] = $component['name'];
    }
  }
  return $options;
}

So I think that there is no way for a "contributed" component to add email form settings through the API, maybe if we add a call to another function in _webform_component_options that can modify the behavior of the $acceptable_types this would be possible. Perhaps adding a extra setting in _webform_defaults_component() API call in order to establish if the component has those email settings could be a good idea too.

What do you think?

quicksketch’s picture

Status: Active » Needs review
StatusFileSize
new4.41 KB

Sounds awesome pcambra! Thanks for taking the initiative on providing this functionality. What you're reporting definitely sounds like a difficiency in the APIs. Here's a patch that extends our existing hook_webform_component_info() to include information about which fields are suitable for e-mail names, addressess, and subjects. All you need to do is add a few extra properties to your implementation of hook_webform_component_info().

quicksketch’s picture

I've committed the patch from #29. In your hook_webform_component_info(), just add the "email_address" feature to your component definition.

pcambra’s picture

Thanks quicksketch! I've updated my module as well including the email_address definition.

roball’s picture

Title: Support for Simplenews module » Public API for allowing other modules to provide components
Status: Needs review » Fixed

Great! Will give it a try maybe when the next beta is out. Thank you quicksketch and pcambra.

roball’s picture

Version: » 6.x-3.0-beta2

Now where the awesome Webform 6.x-3.0-beta2 is out containg this updated API, I am waiting for Webform Simplenews Component's #731614: First beta? to get it tested.

kostajh’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

quicksketch’s picture

Version: 6.x-3.0-beta2 » 6.x-3.0-beta1

Moving this back to beta1 (the version this feature was built-upon), meaning beta 2 was the first version to include it.