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

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

ocStaff (admin)


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 ocPortal on Facebook or add me as a friend.

Expand: Was I helpful? Was I helpful?

Expand: Follow me on Twitter Follow me on Twitter

If I answered something that you think should be in the documentation, please take the initiative and add it to the community documentation. We really need people to help out here and build a well-organised large support resource.
Back to the top
There are too many online users to list.
Control functions:

Quick reply   Contract

Your name:
Your message: