Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

email address verification


ArtcoInc

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

Link to comment
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.

Link to comment
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;  [email protected]

 

There are two letter TLD's from some countries;

 

so someone in (say) Ascension Island might have: [email protected]

 

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

Link to comment
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

Link to comment
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...... ;)

Link to comment
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.

Link to comment
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

Link to comment
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.

Link to comment
Share on other sites

  • 2 months later...

@@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

Link to comment
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://www.oscommerce.com/forums/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

Link to comment
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

Link to comment
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

Link to comment
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

Link to comment
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 

Link to comment
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://www.oscommerce.com/forums/topic/408967-29-days-of-code-here-it-goes-again/?p=1739943

 

Malcolm

Link to comment
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 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...