NewsletterSubscription by justb3a

Allow users to subscribe and unsubscribe to a newsletter.

WARNING: This repository is no longer maintained

This repository will not be updated. The repository will be kept available in read-only mode.

ProcessWire newsletter subscription

Compatibility: ProcessWire 3.x

Allow users to subscribe and unsubscribe to a newsletter.

Subscription flow


The user enters their email address and some other information (if you want to). As soon as the form is submitted a mail is sent to the given address containing a confirmation link (double opt-in). Now the user is added with status hidden and role newsletter. After visiting the confirmation link the user is subscribed (changed status to active).

Unsubscription flow


There are two methods to unsubscribe: by using a web form or by providing a link in the newsletter.

A) using the form

The user enters only their email address and selects the unsubscribe option (if you provide additional fields hide them via JavaScript). If the user submitted a valid and existing email address, a email is sent to this address containing a confirmation link to end subscription. After visiting the link the user is unsubscribed (the user will be deleted).

The user is unsubscribed after visiting the link immediately. You have to generate the link parameters depending on email and userAuthSalt.

Example: https://domain.com/newsletter/?a=unsubscribe&t={sha1($email . $this->config->userAuthSalt)}

Usage


  • install the module

  • create fields which you want to add to the newsletter subscription form

    • if the field should be required, add this in the field settings
    • field email is mandatory and already preselected

  • assign these fields to the user template


  • fill module settings

    • select fields which should be added to the form - save module config
    • select fields which should be used as username
    • if you want to provide an unsubscribe option, activate the according checkbox
    • enter email from address
    • enter how many days the confirmation links should be valid (default 5 days)
    • define email text messages

  • call module

    echo $modules->get('NewsletterSubscription')->render();
  • if you want to add own classes and/or markup, you can pass an option array as a parameter

  • to get an overview of what's possible, have a look at How to overwrite classes and markup

    $options = array (
      'markup' => array(
        'InputfieldSelect' => array(
          'item' => "{out}"
        )
      ),
      'classes' => array(
        'form' => 'form  form__super-special-class',
        'InputfieldRadios' => array(
          'item' => 'form__item--options'
        )
      ),
      'prependMarkup' => "<div>{$page->prepend_markup}</div>,
      'appendMarkup' => "<p>{$page->append_markup}</p>"
    );
    
    echo $modules->get('NewsletterSubscription')->render($options);

Available Keys

keytypedescription
actionstringset specific form action, defaults to same page './'
markuparrayoverwrite markup
classesarrayoverwrite classes
prependMarkupstringprepend some markup/content
appendMarkupstringappend some markup/content

Notify admin via email


If you want to notify any person e.g. administator via email when an user has subscribed/unsubscribed, check the according checkbox in module settings. As soon as you activate this field, some more fields will appear. In these fields you can specify further email messages as well as email receiver and sender. Furthermore you can use placeholders like %email% - even for the receiver email addresses. After the user has visited the confirmation link the admin gets notified.

How to translate


All phrases like email subjects are translatable. Add the module file to the language translator and start translating. Phrases which don't exist in this file belong to the ProcessWire core. For example the messages Please enter a valid e-mail address or Missing required value.

Relevant Files:

  • site/modules/NewsletterSubscription.module
  • wire/modules/Inputfield/InputfieldEmail.module
  • wire/core/InputfieldWrapper.php

Depending on the fields you added to the form there might be some other files.

How to overwrite classes and markup


Below is the list of all available customization options copied from ProcessWire master.

/**
 * Markup used during the render() method
 *
 */
static protected $defaultMarkup = array(
  'list' => "<ul {attrs}>{out}</ul>",
  'item' => "<li {attrs}>{out}</li>",
  'item_label' => "<label class='InputfieldHeader ui-widget-header{class}' for='{for}'>{out}</label>",
  'item_label_hidden' => "<label class='InputfieldHeader InputfieldHeaderHidden ui-widget-header{class}'><span>{out}</span></label>",
  'item_content' => "<div class='InputfieldContent ui-widget-content{class}'>{out}</div>",
  'item_error' => "<p class='InputfieldError ui-state-error'><i class='fa fa-fw fa-flash'></i><span>{out}</span></p>",
  'item_description' => "<p class='description'>{out}</p>",
  'item_head' => "<h2>{out}</h2>",
  'item_notes' => "<p class='notes'>{out}</p>",
  'item_icon' => "<i class='fa fa-fw fa-{name}'></i> ",
  'item_toggle' => "<i class='toggle-icon fa fa-fw fa-angle-down' data-to='fa-angle-down fa-angle-right'></i>",
  // ALSO: 
  // InputfieldAnything => array( any of the properties above to override on a per-Inputifeld basis)
);

/**
 * Classes used during the render() method
 *
 */
static protected $defaultClasses = array(
  'form' => '', // additional clases for InputfieldForm (optional)
  'list' => 'Inputfields',
  'list_clearfix' => 'ui-helper-clearfix',
  'item' => 'Inputfield {class} Inputfield_{name} ui-widget',
  'item_label' => '', // additional classes for InputfieldHeader (optional)
  'item_content' => '',  // additional classes for InputfieldContent (optional)
  'item_required' => 'InputfieldStateRequired', // class is for Inputfield
  'item_error' => 'ui-state-error InputfieldStateError', // note: not the same as markup[item_error], class is for Inputfield
  'item_collapsed' => 'InputfieldStateCollapsed',
  'item_column_width' => 'InputfieldColumnWidth',
  'item_column_width_first' => 'InputfieldColumnWidthFirst',
  'item_show_if' => 'InputfieldStateShowIf',
  'item_required_if' => 'InputfieldStateRequiredIf'
  // ALSO: 
  // InputfieldAnything => array( any of the properties above to override on a per-Inputifeld basis)
);

Install and use modules at your own risk. Always have a site and database backup before installing new modules.

Twitter updates

  • Great video by @jlahijani that demonstrates his ProcessWire page builder using ProFields Repeater Matrix, the new Page Autosave + Live Preview module and Uikit 3— youtube.com/watch?v=Rb5kiU…
    13 November 2021
  • More development on page automatic save this week, plus the addition of live preview— More
    12 November 2021
  • ProcessWire 3.0.189 core updates— More
    5 November 2021

Latest news

  • ProcessWire Weekly #393
    In the 393rd issue of ProcessWire Weekly we'll cover the latest core and module updates, check out a brand new module called Anonymize fields, and highlight some recent tutorials and other online resources. Read on!
    Weekly.pw / 20 November 2021
  • New Repeater and Repeater Matrix features
    This week we have some very useful new additions to both the core Repeater Fieldtype and the ProFields Repeater Matrix Fieldtype. This post covers all the details along with a couple of brief demonstration videos. 
    Blog / 22 October 2021
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits