HTML Logo by World Wide Web Consortium ( Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS. ocPortal 9 is superseded by Composr 10.

Head over to for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.

Patch for main_newsletter_signup block

Login / Search

 [ Join | More ]
 Add topic 
#57385 (In Topic #12476)

Fan in action

EDIT:  Just noting that this is in version 4.2.2 stock

Here's a patch I worked up that fixes some issues that exist with the main_newsletter_signup block and the way it handles invalid email addresses. Unmodified, the block will cause a Critical Error if an invalid email address is input, this includes if a user just pushes the button without editing the default text in the box (which is "Email address" I believe).  This Critical error completely breaks the page and looks…not so good.  Additionally, if an existing email address is entered, the block shows the same text as a new one, but the password is listed as "N/A" which is a bit confusing.  To fix it, I created two additional template files to return for "email address invalid" and "email address already exists"

First I changed


if (!is_valid_email_address($address)) warn_exit(do_lang_tempcode('INVALID_EMAIL_ADDRESS'));


if (!is_valid_email_address($address)) return do_template('BLOCK_MAIN_NEWSLETTER_SIGNUP_INVALID_ADDRESS',array('URL'=>get_self_url()));

allowing one to define a template to be returned in the case of an invalid address, as opposed to killing the page.

I then moved the line



up to directly beneath



and added a new line beneath that


if($password==do_lang('NA')) return do_template('BLOCK_MAIN_NEWSLETTER_SIGNUP_EXISTING_ADDRESS',array('URL'=>get_self_url()));

This will return a template when the address exists in the database, as when that happens basic_newsletter_join() returns do_lang('NA').  Normally you'd get the normal BLOCK_MAIN_NEWSLETTER_SIGNUP_DONE template with an "N/A" in the place where your password would go, which can be pretty confusing to endusers.

I actually also added the fourth parameter to that basic_newsletter_join() call to do email validation on my new newsletter members and send them an email with their password like the default response text implies.

The templates that I reference (BLOCK_MAIN_NEWSLETTER_SIGNUP_EXISTING_ADDRESS and BLOCK_MAIN_NEWSLETTER_SIGNUP_INVALID_ADDRESS) need to be created in order to be used, but overall this leaves the main_newsletter_signup block performing gracefully in any situation.  I've attached my "new" versions of both the module PHP file and my two templates, please feel free to incorporate or use them in any way you'd like.

The contents of those templates are pretty simple:



<p align="center">Email address already subscribed.</p>
<p align="center">Use "Manage Subscription" to change your settings or retrieve your password</p>




<p>That email address is invalid!</p>


Last edit: by dbresnick
Back to the top


Thanks very much for this! It's great to see you contributing.
I've implemented what you brought up - much of it in the same way you did, some of it slightly differently (I try to keep the template count down, so we have 'INLINE_WIP_MESSAGE' for little errors put out by a block).

Become a fan of Composr on Facebook or add me as a friend. Add me on on Twitter. Support me on Patreon
Was I helpful?
  • If not, please let us know how we can do better (please try and propose any bigger ideas in such a way that they are fundable and scalable).
  • If so, please let others know about Composr whenever you see the opportunity or support me on Patreon.
  • If my reply is too Vulcan or expressed too much in business-strategy terms, and not particularly personal, I apologise. As a company & project maintainer, time is very limited to me, so usually when I write a reply I try and make it generic advice to all readers. I'm also naturally a joined-up thinker, so I always express my thoughts in combined business and technical terms. I recognise not everyone likes that, don't let my Vulcan-thinking stop you enjoying Composr on fun personal projects.
  • If my response can inspire a community tutorial, that's a great way of giving back to the project as a user.
Back to the top
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: