Jump to content
ArtcoInc

email address verification

Recommended Posts

I am working on updating an older add-on, Newsletters Subscribers Manager

 

http://addons.oscommerce.com/info/8472

 

(As written, it uses a box in either the left column or right column, although I have revised it so it can also be a footer content module)

 

There is an entry field where the customer can enter their email address. The add-on uses its own javascript for verifying that the email address entered is valid.

    function execute() {
      global $oscTemplate;

$VerifierMailBoxe = '<script type="text/javascript">
   function VerifierMailBoxe(form) {
       if (form.emailsubscription.value == "" ) {
           alert("' . BOX_NEWSLETTER_ERROR_EMPTY_FIELD . '")
           form.emailsubscription.focus();
           return false;
          }

       else if (form.emailsubscription.value.indexOf(",") > 0) {
           alert("' . BOX_NEWSLETTER_ERROR_COMMA . '")
           form.emailsubscription.focus();
           return false;
          }

       else if (form.emailsubscription.value.indexOf(" ") > 0) {
           alert("' . BOX_NEWSLETTER_ERROR_SPACES . '")
            form.emailsubscription.focus();
           return false;
           }

       else if (form.emailsubscription.value.indexOf("@") < 0) {
           alert("' . BOX_NEWSLETTER_ERROR_SIGN . '")
           form.emailsubscription.focus();
           return false;
          }

       else if (form.emailsubscription.value.lastIndexOf(".") < 0) {
           alert("' . BOX_NEWSLETTER_ERROR . '")
           form.emailsubscription.focus();
           return false;
          }

       else if ((form.emailsubscription.value.length - 1) - form.emailsubscription.value.lastIndexOf(".") < 2) {
           alert("' . BOX_NEWSLETTER_ERROR . '")
           form.emailsubscription.focus();
           return false;
          }

       else {
          // form.submit()
           return true;
          }
   }
</script>';

      $data = $VerifierMailBoxe . '<div class="panel panel-default">' .
                                  '  <div class="panel-heading">' .
                                       MODULE_BOXES_NEWSLETTER_BOX_TITLE .
                                  '  </div>' .
                                  '  <div class="panel-body text-center">' .
                                       tep_draw_form('newslettersubscription', tep_href_link(FILENAME_NEWSLETTER_SUBSCRIPTION, '', 'NONSSL'), 'post', 'onSubmit="return VerifierMailBoxe(this);"') .                                        tep_draw_input_field('emailsubscription', '', 'placeholder="' . BOX_NEWSLETTER_TEXT_EMAIL .'" size="15" maxlength="50"') .
                                         tep_draw_button(IMAGE_BUTTON_NEWSLETTER_SUBSCRIPTION, 'glyphicon glyphicon-envelope', null, 'primary') .
                                  '    </form>' .
                                  '  </div>' .
                                  '</div>';

          $oscTemplate->addBlock($data, $this->group);
    }

While this works (sort of), I have found bad email addresses that pass the test. Besides, osC has its own built-in function, tep_validate_email(). So, I would like to revise this to use tep_validate_email(), but I have no idea how to do this. I have looked at other places that use this function ( such as create_account.php and account_edit.php ), but neither of these are boxes or modules. Can someone point me in the right direction?

 

TIA

 

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

Hey Malcolm,

 

Can you put your whole file here so I can experiment with it?  I think I can help you get the tep_validate_email funtion to work.

Edited by John W

I'm not really a dog.

Share this post


Link to post
Share on other sites

@@burt

 

The tep_validate_email() function caught the email address a@b stating that an email address must be at least 6 characters

 

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

You might want to look at the password reset file for inspiration, but you would need to scrap a lot of what you've done.  Food for thought is not adding more inline javascript is a plus to using something like password reset.  No matter what you'll still get some bad emails even if it's RFC compliant it can be wrong and people make mistakes.


I'm not really a dog.

Share this post


Link to post
Share on other sites

@@burt

 

The tep_validate_email() function caught the email address a@b stating that an email address must be at least 6 characters

 

Malcolm

 

In real life the shortest possible I can think of is something like;  x@x.xxx

 

There are two letter TLD's from some countries;

 

so someone in (say) Ascension Island might have: a@b.ac

 

However, if a@b is RFC compliant...then that is a possible email address.


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

@@John W @@burt

 

Call me stubborn, but I'm still trying to get the tep_validate_email() function to work within a module. I'm probably heading down a bad path, but that's what happens when I don't know what I'm doing :-

 

Two questions:

 

1) How can a box or module know what page is being displayed, since the box or module may be shown on just about any page?

 

2) Can I use $messageStack within a box or module to display errors? If so, can someone show me an example?

 

TIA

 

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

1.  $PHP_SELF 

eg:

https://github.com/gburton/Responsive-osCommerce/blob/master/includes/modules/boxes/bm_currencies.php#L34

https://github.com/gburton/Responsive-osCommerce/blob/master/includes/modules/boxes/bm_currencies.php#L36

 

34 lets the box see it

36 is using it

 

2.  as is done at https://github.com/gburton/Responsive-osCommerce/blob/master/includes/application_top.php#L350-L351

messagestack is called.  it shows on the next page load.

 

I still think that you should use up-to-date HTML5 technology...... ;)


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

I have to say most of the invalid email addresses I get would pass these test.  Mostly, people have typos before the @.  OnceI added confirm email address to make sure they matched that helped but I still get some.  But, it sounds like you're using this as an excercise in learning, which is always good.


I'm not really a dog.

Share this post


Link to post
Share on other sites

In addition to "validate" an email address, I also wanted to check to see if the customer had already signed up for the newsletter, and notify them of this fact. This add-on uses the stock newsletter_subscription.php and newsletter_subscription_success.php files. While these won't *add* a duplicate email address, they just tell the customer that they have been added, and doesn't inform the customer that they were already subscribed. To change this would mean 'core changes', which we're trying not to do. While this may have been a nice addition to the add-on, it isn't necessary. So, I'm moving on.

 

@@burt

 

I've taken your (usually wise) advice, and dropped my efforts to do any manual email validation, and instead will use the HTML5 technology.

 

 

@@John W

 

As a exercise in learning, I've learned that I don't know what I'm doing :-

 

 

Thank you both for your assistance. 

 

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

In addition to "validate" an email address, I also wanted to check to see if the customer had already signed up for the newsletter, and notify them of this fact. This add-on uses the stock newsletter_subscription.php and newsletter_subscription_success.php files. While these won't *add* a duplicate email address, they just tell the customer that they have been added, and doesn't inform the customer that they were already subscribed. To change this would mean 'core changes', which we're trying not to do. While this may have been a nice addition to the add-on, it isn't necessary. So, I'm moving on.

 

Changing these newsletter_*.php files would not be considered core changes...

 

What you need is a HT module that has some .js in it that links to a checker for the email address.  

Definitely possible.  Sounds very like something I made a while back.

 

As for "usually wise"...hahaha, "usually a idiot who says too much" is more like it.


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

@@burt

 

I know *zip* about .js, so I'm going to call this exercise done, and go hit the shower ...

 

Thanks, though!

 

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

@@ArtcoInc  Malcolm...I know you've moved on but I'm wondering if you considered adding an double opt-in routine while you were playing around with this?....ie the customer is sent an email and asked to confirm they want to join your list...if the address isn't valid they won't receive the email and the table isn't updated to indicate that it is a valid email address verified by the double opt-in process.

 

Dan

Share this post


Link to post
Share on other sites

@@Dan Cole

@@ArtcoInc  Malcolm...I know you've moved on but I'm wondering if you considered adding an double opt-in routine while you were playing around with this?....ie the customer is sent an email and asked to confirm they want to join your list...if the address isn't valid they won't receive the email and the table isn't updated to indicate that it is a valid email address verified by the double opt-in process.

 

Dan

 

Dan,

 

I had not considered that. I can see how that would definitely rule out any invalid email addresses ... if the customer doesn't reply to an email sent to the address, either the address isn't valid, or the customer doesn't want to be on the mailing list.

 

As I see it, it would have to have some sort of token sent in the email, so the customer's answer could be linked to the initial mailing list request. I know that @@burt has some code to handle this ...

 

http://forums.oscommerce.com/topic/410262-addons/?p=1750787

 

But, I do not have a mailing list on any of my stores. I tackled this primarily as a learning experience, and it rapidly grew beyond my programming skill level (and available 'spare' time).

 

Please feel free to pick this up and run with it, if you so choose. B)

 

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

@ArtcoIncThanks for the reply Malcolm....it is on my todo, or at least my to attempt list....I hate reinventing the wheel so I thought I had better ask before I jumped in.

 

Dan

Share this post


Link to post
Share on other sites

considered adding an double opt-in routine

Assuming that here we are talking about Mailchimp ... you do this as so;

 

1. never update the DB (newsletter from within the shop side)

2. set double optin to true

3. set up webhook


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

Assuming that here we are talking about Mailchimp ... you do this as so;

 

1. never update the DB (newsletter from within the shop side)

2. set double optin to true

3. set up webhook

@@burt I was actually thinking about doing this within osC.   Ultimately I want to be able to send targeted emails...ie brand and product specific emails based on past sales history etc. I may build the lists internally and then export them to a service like Mailchimp.   I can't see how I would do this using a external list since it will need the shop data to generate the mailing list.

 

Dan

Share this post


Link to post
Share on other sites

Ah OK. I suspect that this might rather be a job for emails rather than for newsletters...

 

So, let us say that you have a page in admin on which you can set up certain parameters:

 

show me customers who bought product X

- send an email to these customers letting them know of a new version

 

show me customers who bought any product from Y brand

- send an email letting them know of a new product from this brand

 

show me customers who have a birthday in the next quarter

- send them email with a happy birthday discount


Help shape the future of Phoenix; join the Phoenix Club

Share this post


Link to post
Share on other sites

@@burt

I see this being useful.  Being able to target customers by certain products is something I had thought about too. 


I'm not really a dog.

Share this post


Link to post
Share on other sites

Ah OK. I suspect that this might rather be a job for emails rather than for newsletters...

 

So, let us say that you have a page in admin on which you can set up certain parameters:

 

show me customers who bought product X

- send an email to these customers letting them know of a new version

 

show me customers who bought any product from Y brand

- send an email letting them know of a new product from this brand

 

show me customers who have a birthday in the next quarter

- send them email with a happy birthday discount

 

Newsletter is probably not the right term...email marketing is more like it but yes that is exactly the sort of thing I had in mind.  My thinking is that having a single mailing list of both customer emails and say prospects/newsletter subscribers would enable me to do this sort of thing as well as being able to make full mailing list offers for holiday specials, I'm desperate offers etc.

 

Dan 

Share this post


Link to post
Share on other sites

@@Dan Cole

@@ArtcoInc  Malcolm...I know you've moved on but I'm wondering if you considered adding an double opt-in routine while you were playing around with this?....ie the customer is sent an email and asked to confirm they want to join your list...if the address isn't valid they won't receive the email and the table isn't updated to indicate that it is a valid email address verified by the double opt-in process.

 

Dan

 

Like this?

 

http://forums.oscommerce.com/topic/408967-29-days-of-code-here-it-goes-again/?p=1739943

 

Malcolm


Get the latest Responsive osCommerce CE (community edition) here .

Share this post


Link to post
Share on other sites

@@ArtcoInc  I'm sure that could work...the usual way is to send the subscriber an email...they just hit reply or click on a confirmation link in the email.  When the confirmation is received it updates the database indicating that the email has been confirmed. When I build the double opt in routine on the osC side of the module I'll take a closer look at his routine...I don't know that we need them to actually type the code in a new page but having them click on a link provided in the email, like he does in the key review module, would probably work nicely.

 

Dan 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×