ArtcoInc Posted September 27, 2016 Share Posted September 27, 2016 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 Quote Link to comment Share on other sites More sharing options...
♥John W Posted September 27, 2016 Share Posted September 27, 2016 (edited) 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 September 27, 2016 by John W Quote I'm not really a dog. Link to comment Share on other sites More sharing options...
burt Posted September 27, 2016 Share Posted September 27, 2016 This can all be done in HTML5. Simply make "email" the type of input. Eg: https://github.com/gburton/Responsive-osCommerce/blob/master/includes/modules/content/login/templates/login_form.php#L11 Further reading: https://www.w3.org/TR/html-markup/input.email.html http://www.htmlgoodies.com/html5/tutorials/whats-new-in-html5-forms-email-url-and-telephone-input-types.html Quote Link to comment Share on other sites More sharing options...
ArtcoInc Posted September 27, 2016 Author Share Posted September 27, 2016 @@burt Thank you. I tried that, and while it did catch many bad email addresses, it did let at least one through (which the javascript code did catch): a@b @@John W bm_newsletters.php Malcolm Quote Link to comment Share on other sites More sharing options...
burt Posted September 27, 2016 Share Posted September 27, 2016 a@b is RFC compliant... Which doesn't make sense, but there we are. Quote Link to comment Share on other sites More sharing options...
ArtcoInc Posted September 27, 2016 Author Share Posted September 27, 2016 Learn something new every day B) Quote Link to comment Share on other sites More sharing options...
ArtcoInc Posted September 27, 2016 Author Share Posted September 27, 2016 @@burt The tep_validate_email() function caught the email address a@b stating that an email address must be at least 6 characters Malcolm Quote Link to comment Share on other sites More sharing options...
♥John W Posted September 27, 2016 Share Posted September 27, 2016 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. Quote I'm not really a dog. Link to comment Share on other sites More sharing options...
burt Posted September 27, 2016 Share Posted September 27, 2016 @@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. Quote Link to comment Share on other sites More sharing options...
ArtcoInc Posted September 28, 2016 Author Share Posted September 28, 2016 @@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 Quote Link to comment Share on other sites More sharing options...
burt Posted September 29, 2016 Share Posted September 29, 2016 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...... ;) Quote Link to comment Share on other sites More sharing options...
♥John W Posted September 29, 2016 Share Posted September 29, 2016 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. Quote I'm not really a dog. Link to comment Share on other sites More sharing options...
ArtcoInc Posted September 29, 2016 Author Share Posted September 29, 2016 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 Quote Link to comment Share on other sites More sharing options...
burt Posted September 29, 2016 Share Posted September 29, 2016 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. Quote Link to comment Share on other sites More sharing options...
ArtcoInc Posted September 29, 2016 Author Share Posted September 29, 2016 @@burt I know *zip* about .js, so I'm going to call this exercise done, and go hit the shower ... Thanks, though! Malcolm Quote Link to comment Share on other sites More sharing options...
Dan Cole Posted December 14, 2016 Share Posted December 14, 2016 @@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 Quote Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
ArtcoInc Posted December 14, 2016 Author Share Posted December 14, 2016 @@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 Quote Link to comment Share on other sites More sharing options...
Dan Cole Posted December 14, 2016 Share Posted December 14, 2016 @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 Quote Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
burt Posted December 15, 2016 Share Posted December 15, 2016 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 Quote Link to comment Share on other sites More sharing options...
Dan Cole Posted December 15, 2016 Share Posted December 15, 2016 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 Quote Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
burt Posted December 15, 2016 Share Posted December 15, 2016 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 Quote Link to comment Share on other sites More sharing options...
♥John W Posted December 15, 2016 Share Posted December 15, 2016 @@burt I see this being useful. Being able to target customers by certain products is something I had thought about too. Quote I'm not really a dog. Link to comment Share on other sites More sharing options...
Dan Cole Posted December 15, 2016 Share Posted December 15, 2016 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 Quote Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
ArtcoInc Posted December 22, 2016 Author Share Posted December 22, 2016 @@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 Quote Link to comment Share on other sites More sharing options...
Dan Cole Posted December 23, 2016 Share Posted December 23, 2016 @@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 Quote Need help? See this thread and provide the information requested. Is your version of osC up to date? You'll find the latest osC community version (CE Phoenix) here. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.