X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Using Javascript to confirm email address? (https://forum.x-cart.com/showthread.php?t=7396)

xcell67 05-01-2004 02:09 AM

Using Javascript to confirm email address?
 
In order to cut back on mistyped email addresses and customers complaining about not receiving an order confirmation because they didn't type their email correctly, I was thinking about having an added filed to the registration.

Email Address and the new: Confirm Email address

I was trying to see if I could implement the other java validations already there, ie zipcode validation but that didn't seem to work. How does the password and confirm password validation work? I couldn't find any java code for it.

Thanks for reading, I think this is a much needed feature.

adpboss 05-01-2004 07:39 AM

This is a problem in every store, specifically for someone like me who deals with adolescent boys and young men. People who cannot be bothered to type their name, address or email properly.

This would be a nice feature.

xcell67 05-21-2004 07:34 PM

I created a new field "email2" and tried adding this code to include/register.php

Code:

function validate($email, $email2, ==)
{
    if($email == $email2)
    {
        return true;
    } else {
        return false;
    }
}


but then i got a page error when trying to use register on the customer side, I think i have to try to implement it into register.tpl rather than register.php, anyone know how to make the above code smarty friendly?

thanks

Mod King 05-21-2004 08:55 PM

You could do some javascript regex checking before they submit the form

But i am not sure on your intetions, did you want to make it so that they enter 2 e-mail addresses and you compare them?

If so you have to add both fields to register.tpl

Then you *should* be able to use them in register.php
if you have any problems just bug me :)
i'm around alot.

B00MER 05-21-2004 09:19 PM

First edit skin1/check_email_script.tpl, replace its entire contents with:

Code:

{* $Id: check_email_script.tpl,v 1.6.2.2 2004/03/26 09:47:33 svowl Exp $ *}
{literal}
<script language="JavaScript1.2">
function checkEmailAddress(field) {

var goodEmail = field.value.search(/^[A-Za-z0-9]{1}([A-Za-z0-9_\-\.]+)[^\.]\@[^\.]([A-Za-z0-9_\-\.]+\.)+[A-Za-z]{2,6}[ ]*$/gi);
if (goodEmail!=-1) {
        if(field.value==document.registerform.emailtwo.value) {
    return true;
  } else {
          alert("Email's do not match, please correct!");
          document.registerform.emailtwo.focus();
          document.registerform.emailtwo.select();
          return false;
  }

} else {
{/literal}
        alert("{$lng.txt_email_invalid|replace:"\n":" "|replace:"\r":" "}");
{literal}
        field.focus();
        field.select();
        return false;
    }
}
</script>
{/literal}


Now open up skin1/main/register_contact_info.tpl and underneath the email table row (</tr>) add this:

Code:

<tr valign=middle>
<td align=right>Validate {$lng.lbl_email}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=emailtwo size=32 maxlength=128 value="{$userinfo.email}">
</td>
</tr>


This way your not inserting two emails into the database but rather making sure the user has entered the same values into the email field incase of misstypes. All javascript based. ;)

:!: Above code was written with 3.5.x

xcell67 05-23-2004 08:12 PM

works like a charm,

THANK YOUUUUUUUUUU BOOOMER!

adpboss 05-23-2004 08:16 PM

Should be standard in X-Cart. RRF are you awake right now? ;)

xcell67 05-25-2004 08:53 PM

Ah, this was the culprit! After a day of modding I wasn't able to test the gift certificate purchase. I finally found out that this javascript although very effective for validating the email during checkout and register (thank you Boomer) does not allow a gift cert to be purchased. I tried to see if other functions that require email such as contact us had the same problem but it was only gift certificates.

Boomer, Could you modify the java code to exclude its effect on giftcerts or could you tell me what I would have to add to giftcert.tpl for it to work properly?

Thanks

B00MER 05-26-2004 07:42 AM

Duplicate the original skin1/check_email_script.tpl and rename it for the modified one and change the include in the register tpl

Loon 05-26-2004 09:28 AM

For a little more explicite directions, for those of us "code challenged", along with the two code updates above from Boomer (call them step 1 and step 2), do this to make the gift certificate email validation operational also:

Step 3: create a new file called [cart directory]/skin1/check_gcemail_script.tpl with contents:

Code:

{* $Id: check_gcemail_script.tpl,v 1.6.2.2 2004/03/26 09:47:33 svowl Exp $ *}
{literal}
<script language="JavaScript1.2">
function checkGCEmailAddress(field) {

var goodEmail = field.value.search(/^[A-Za-z0-9]{1}([A-Za-z0-9_\-\.]+)[^\.]\@[^\.]([A-Za-z0-9_\-\.]+\.)+[A-Za-z]{2,6}[ ]*$/gi);
if (goodEmail!=-1) {
  if(field.value==document.gccreate.emailtwo.value) {
    return true;
  } else {
    alert("Email's do not match, please correct!");
    document.gccreate.emailtwo.focus();
    document.gccreate.emailtwo.select();
    return false;
  }

} else {
{/literal}
        alert("{$lng.txt_email_invalid|replace:"\n":" "|replace:"\r":" "}");
{literal}
        field.focus();
        field.select();
        return false;
    }
}
</script>
{/literal}


Step 4: in the file [cart directory]/skin1/modules/Gift_Certificates/giftcert.tpl
changed include on line 3 to call my new file for giftcert email validation:
replace:
Code:

{include file="check_email_script.tpl"}
with:
Code:

{include file="check_gcemail_script.tpl"}

around line 29, to call the new function created in Step 3 above:
replace:
Code:

if ((document.gccreate.send_via[0].checked) && (!checkEmailAddress(document.gccreate.recipient_email)))
with:
Code:

if ((document.gccreate.send_via[0].checked) && (!checkGCEmailAddress(document.gccreate.recipient_email)))

around line 203, ADD the second email field to the gift certificate purchase form, with a few changes from the one in the registration form:

Code:

<tr>
<td nowrap align=right>Validate {$lng.lbl_email}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=emailtwo size=32 maxlength=128 value="{$giftcert.recipient_email}">
</td>
</tr>


Please Note that I have not thoroughly tested everything. The contact us form still works fine, gift cert purchase works fine, registration (thanks Boomer) works fine. Please post here if you find other problems.

Jean

GM 05-26-2004 02:00 PM

It's friggin' scary how smart you guys are! Especially you BOOMER (where were you born? Earth?) :wink:
And thanks Loon for thinking of guys like me :D

Loon 05-26-2004 02:44 PM

Thanks, but if you think I'm so smart (2nd smartest, of course, and I accept that Very Gracefully), why can't I apply the upgrade from 3.5.4 to 3.5.6 without losing all the images? It's about to drive me around the bend!

I've probably been doing this sort of stuff since before you were born, unfortunately, so if it weren't for the Smarty templates, it would all be a breeze. Hard to teach an old dog new tricks.

Glad, though, that someone appreciates the easy directions.

J. a.k.a. Loon

P.S. since my previous post here, I've installed in production, created a profile, modified it, bought a gift cert and deleted the profile and everything works flawlessly [she said].

GM 05-26-2004 03:53 PM

UPDATE: Something in the check_email_script.tpl is causing the gift cert part not to funtion at all in 3.5.7. ie: when you click submit... nothing.
Or should I say that the GC part in 3.5.7 is somehow relying on check_email_script.tpl when it should be relying on check_gcemail_script.tpl ??? I better try this again.

2nd UPDATE: Nope, it's not me, BOOMERS side is working but the GC side isn't working in 3.5.7

Loon 05-26-2004 05:12 PM

If it would help, I can send you my two files that I altered for the gift cert stuff and you can do a file compare .... since I'm still on 3.5.4, something else may be in play here.... let me know. J.

GM 05-26-2004 05:16 PM

Ok... found it! In v3.5.7 you also need to change line 46 in giftcert.tpl from:
Code:

if (!checkEmailAddress(document.gccreate.recipient_email))

To:

Code:

if (!checkGCEmailAddress(document.gccreate.recipient_email))

Works awesome you guys! Great Mod! should be standard in the cart.

Loon 05-27-2004 04:25 AM

Hey, good catch. We allow people to order gift certs to be mailed to them (US Postal mail) so I think that's why I never hit the piece of code you fixed.

This needs to be fixed in version 3.5.4 also.

Together, we can do it! J.

GM 05-27-2004 07:37 AM

Small revision (cleans it up a bit)

in skin1/modules/Gift_Certificates/giftcert.tpl

"around line 203, ADD the second email field to the gift certificate purchase form, with a few changes from the one in the registration form:"

Changed to:
Code:




<tr>
<td nowrap align=right>Validate {$lng.lbl_email}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=emailtwo size=30 value="{$giftcert.recipient_email}">
</td>
</tr>


B00MER 06-07-2004 04:02 PM

Updated check_email_script.tpl this should prevent any problems with Gift Certificates as well as Affiliate registrations also:

Code:

{* $Id: check_email_script.tpl,v 1.6.2.2 2004/03/26 09:47:33 svowl Exp $ *}
{literal}
<script language="JavaScript1.2">
function checkEmailAddress(field) {

var goodEmail = field.value.search(/^[A-Za-z0-9]{1}([A-Za-z0-9_\-\.]+)[^\.]\@[^\.]([A-Za-z0-9_\-\.]+\.)+[A-Za-z]{2,6}[ ]*$/gi);
if (goodEmail!=-1) {

        if(document.registerform.emailtwo) {
                if(field.value==document.registerform.emailtwo.value) {
            return true;
          } else {
                  alert("Email's do not match, please correct!");
                  document.registerform.emailtwo.focus();
                  document.registerform.emailtwo.select();
                  return false;
          }
        } else {
                return true;
        }

} else {
{/literal}
        alert("{$lng.txt_email_invalid|replace:"\n":" "|replace:"\r":" "}");
{literal}
        field.focus();
        field.select();
        return false;
    }
}
</script>
{/literal}


sanj-xcart 10-13-2005 02:27 PM

This is invaluable, thanks all. I'm working with 4.016, so I couldn't directly copy the code above. My check_email_script now looks like the following (bold was added to original):

Code:

{* $Id: check_email_script.tpl,v 1.11.2.6 2004/11/22 09:16:26 max Exp $ *}
{literal}
<SCRIPT type="text/javascript" language="JavaScript 1.2">
function checkEmailAddress(field, empty_err) {
var err = false;
var res, x;
        if(!field)
                return true;

        if(field.value.length == 0) {
                if(empty_err != 'Y')
                        return true;
                else
                        err = true;
        }

        var arrEmail = field.value.split('@');
        if(arrEmail.length != 2 || arrEmail[0].length < 1)
                err = true;
        if(!err) {
                if(arrEmail[0].length > 2)
                        res = arrEmail[0].search(/^[-\w][-\.\w]+[-\w]$/gi);
                else
                        res = arrEmail[0].search(/^[-\w]+$/gi);
                if(res == -1)
                        err = true;
        }
        if(!err) {
                var arr2Email = arrEmail[1].split('.');
                if(arr2Email.length < 2)
                        err = true;
        }
        if(!err) {
                var domenTail = arr2Email[arr2Email.length-1];
                var _arr2Email = new Array();
                for(x = 0; x < arr2Email.length-1; x++)
                        _arr2Email[x] = arr2Email[x];
                arr2Email = _arr2Email;
                var domen = arr2Email.join('.');
                res = domen.search(/^[-!#\$%&*+\\\/=?\.\w^`{|}~]+$/gi);
                if(res == -1)
                        err = true;
                res = domenTail.search(/^[a-zA-Z]+$/gi);
                if(res == -1 || domenTail.length < 2 || domenTail.length > 6)
                        err = true;
        }
//        /^([-\w][-\.\w]*)?[-\w]@([-!#\$%&*+\\\/=?\w^`{|}~]+\.)+[a-zA-Z]{2,6}$/gi

        if (err) {
                alert({/literal}"{$lng.txt_email_invalid|replace:"\n":" "|replace:"\r":" "|replace:'"':'\"'}"{literal});
                field.focus();
                field.select();
        }
        [b]
    if(document.registerform.emailtwo) {
      if(field.value==document.registerform.emailtwo.value){ }
          else{
        alert("Please reconfirm your email address. It does not match.");
        document.registerform.emailtwo.focus();
        document.registerform.emailtwo.select();
                err = true;
          }
  }
  [/b]       
        return !err;
}
</SCRIPT>
{/literal}


I followed the second step exactly as above, inserting the following just under the email input in the register_contact_info.tpl file:

Code:

<TR>
<TD align="right">{$lng.lbl_confirm_email}</TD>
<TD><font class=Star>*</font></TD>
<TD nowrap>
<input type="text" id="emailtwo" name="emailtwo" size=32 maxlength=128 value="{$userinfo.email}">
</TD>
</TR>


Thanks for the great code and tips folks, I really appreciate it.

sanj-xcart 10-13-2005 02:31 PM

Sorry, I just noticed that bold doesn't show up in code. You will need to extract the bbcode bold tags from the first script if you use it.

Also, I have only used this for standard customer registration. It works there, but I have not tested with Gift Certificates or Affiliates, so please be aware of this.

sanj

Loon 10-18-2005 03:00 PM

We've had several problems with the regular expression that checks if the email is valid --
I changed in skin1/check_email_script.tpl and skin1/check_gcemail_script.tpl, this line:
New Code to replace old:
Code:

var goodEmail = field.value.search(/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/gi);

The first reiteration of this check would not allow someone with a 2 character email to register (invalid email address for ed@somewhere.net)

I tweaked it a little and then heard from a customer on RedHat Linux, Netscape 7.1, that it wouldn't allow her to register AND no error - the submit button just didn't do anything. I loaded up the browser on Fedora and sure enough, there was a javascript error. It worked fine in Netscape 7.1 on a Windows box ... weird.

Anyway, the above will allow a 1 character email name, a 1 character domain (a.com if it existed) and ed@somewhere.ca can now register.

Give yours a try on Linux with Netscape 7.1 if you can, or try to create a profile using a two character user name ... you may have the same problem.

sanj-xcart 10-18-2005 09:46 PM

Thanks for the tips.

I didn't have problems registering a 2 character email address (perhaps they have modified the regex code since 3.5), but I'm unable to check the second problem involving Netscape 7.1.

Definitely something to be aware of. Thanks.

sunny 04-05-2006 07:36 AM

email verification
 
Don't know if anyone monitors past threads but here goes...

I used this portion of code on a version 4.0.12 cart and while it works great - thanks so much - I wonder what all the other code in check_email_script.tpl that was replaced was doing. Was replacing all this code still the correct thing to do?

Thanks in advance.

Sunny

jcasella 11-28-2006 07:21 PM

Re: Using Javascript to confirm email address?
 
Hi,

I know this is an old topic, but I wanted to write in to say THANK YOU to Boomer, Loon, and GM for supplying these mods with such straightforward instructions. This is a feature we've been dreaming of, and will be a huge help in accidental email address typos with our customers. More Egoods will now find their rightful owners.

Thanks again!

eLuminateMedia 08-26-2010 06:05 AM

Re: Using Javascript to confirm email address?
 
Quote:

Originally Posted by B00MER
First edit skin1/check_email_script.tpl, replace its entire contents with:

Code:

{* $Id: check_email_script.tpl,v 1.6.2.2 2004/03/26 09:47:33 svowl Exp $ *}
{literal}
<script language="JavaScript1.2">
function checkEmailAddress(field) {
 
var goodEmail = field.value.search(/^[A-Za-z0-9]{1}([A-Za-z0-9_\-\.]+)[^\.]\@[^\.]([A-Za-z0-9_\-\.]+\.)+[A-Za-z]{2,6}[ ]*$/gi);
if (goodEmail!=-1) {
    if(field.value==document.registerform.emailtwo.value) {
    return true;
  } else {
      alert("Email's do not match, please correct!");
      document.registerform.emailtwo.focus();
      document.registerform.emailtwo.select();
      return false;
  }
 
} else {
{/literal}
        alert("{$lng.txt_email_invalid|replace:"\n":" "|replace:"\r":" "}");
{literal}
        field.focus();
        field.select();
        return false;
    }
}
</script>
{/literal}


Now open up skin1/main/register_contact_info.tpl and underneath the email table row (</tr>) add this:

Code:

<tr valign=middle>
<td align=right>Validate {$lng.lbl_email}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=emailtwo size=32 maxlength=128 value="{$userinfo.email}">
</td>
</tr>


This way your not inserting two emails into the database but rather making sure the user has entered the same values into the email field incase of misstypes. All javascript based. ;)

:!: Above code was written with 3.5.x


I can't seem to get this working any ideas what I might be doing wrong, I am quite new to Xcart but have been a web designer for some time.
I have checked a few times and seem to be following everything fine. I don't see the extra field etc.


All times are GMT -8. The time now is 12:08 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.