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)
-   -   ZipCode Validation Module (https://forum.x-cart.com/showthread.php?t=7888)

NuAlpha 06-12-2004 02:05 PM

:lol: Don't worry about it! We're all guilty of asking newbie questions from time to time. :-$

GM 06-12-2004 02:29 PM

I noticed that spaces where counted as characters with this script. ie: P0H A0 would be 6 characters. This is a problem with Canadian codes. We use 6 characters and a space (P0H 1A0). The script won't catch that error. If I type in P0H A0 the script will allow it. Is there any way to ignore the space? ie:
P0H1A0 = correct
P0H 1A0 = correct
P0H A0 = incorrect

I hope there's a way around this? I'm obviously not smart enough to figure it out (I couldn't even find the check_zipcode_js template 8O )

NuAlpha 06-12-2004 02:34 PM

I will have to take a look at it. I can't do anything with it right now as I have more pressing matters to attend to, but I should have it worked out before the weekend is over.

NuAlpha 06-12-2004 02:39 PM

Okay, quick attempt at a fix.

Replace...
Code:

if (preg_match("/^([A-z0-9]{3})([-._\/\ ])([A-z0-9]{3})(.)?/i", $zipcode, $checkZip)) {

...with...
Code:

if (preg_match("/^([A-z0-9]{3,3})([-._\/\ ])([A-z0-9]{3,3})(.)?/i", $zipcode, $checkZip)) {

Let me know if this fixes it. If not, I will look at it more thoroughly tomorrow.

GM 06-12-2004 05:54 PM

NuAlpha I'm gonna' try it... but wether it works or not... YOU ROCK! http://www.goldmisers.com/smiles/thumbsup.gif

[UPDATE] Didn't work, but I've used a mod (from this forum) in my register.tpl that causes the Postal Code to display in caps and I'm wondering if it could be messing things up? Can't see it but maybe you can... here it is:
Code:

<tr valign=middle>
<td align=right>{$lng.lbl_zip_code}</td>
<td><font class=Star>*</font></td>
<td nowrap>
<input type=text name=b_zipcode size=32 maxlength=32 value="{$userinfo.b_zipcode}" onKeyUp="this.value=this.value.toUpperCase()" onChange="check_zip_code()" >
{if $reg_error ne "" and $userinfo.b_zipcode eq ""}<font class=Star>&lt;&lt;</font>{/if}
</td>
</tr>


NuAlpha 06-12-2004 07:54 PM

It's not likely to be messing it up. Though the Canadian postal code validation code already formats the zipcode as upper case before returning the result to register.php.

I am fairly perplexed at why this is happening because the regex check should evaluate as '0' (false) if the postal code lacks the format: alphanum-space-alphanum

Where I am it is nearly midnight as of this post and nothing is immediately obvious, so I will have get back to you in the morning.

Anybody else care to take a stab from a fresh perspective at what could be wrong?

NuAlpha 06-14-2004 07:09 AM

First of all, make sure you install the "check_zipcode_js.tpl" as that should notify people that their postal code is the wrong length as soon as they leave the field.

I couldn't duplicate the problem on my end but I did find a better way to write the code in any case. Here is the update...
Code:

<?php
#########################################
##      ## Validate Zipcode ##        ##
#########################################
## Version: 1.2.7 (3/2/2004)
## Last updated: 6/13/2004

if (!defined('XCART_SESSION_START')) { header("Location: ../"); die("Access Denied!"); }

function validate_zipcode($zipcode,$country='') {
       
        $zipcode = trim($zipcode); // Prep by removing excess spaces.
       
        switch ($country) {
        case 'US': // Validate United States postal codes.
                if (strlen($zipcode) > 5 && strlen($zipcode) <= 10) { // If not length 5, then check for valid format.
                        if (preg_match("/^([0-9]{5})([-=._\/\ ])?([0-9]{4})?$/", $zipcode, $checkZip)) {
                                if (!empty($checkZip[3])) { // Is it a zip+4 code?
                                        if (empty($checkZip[2]) || $checkZip[2] != '-')
                                                $checkZip[2] = '-'; // Ensure that a dash is present in 9 digit zip code.
                                        $zipcode = $checkZip[1].$checkZip[2].$checkZip[3];
                                } else // Cause an error from incorrect length.
                                        $zipcode = '';
                        } else // No valid zip code matched.
                                $zipcode = '';
                } elseif (strlen($zipcode) < 5 || preg_match("/[[:alpha:]]/i",$zipcode)) // Check min length or presence of a letter.
                        $zipcode = '';
                # If none of the above, do not modify zipcode. It is a valid 5 numeric digits.
                break;
        case 'CA': // Validate Canadian postal codes.
                if (strlen($zipcode) >= 6 && strlen($zipcode) <= 7) { // Check for valid length.
                        if (preg_match("/^([A-z0-9]{3})([-._\/\ ])([A-z0-9]{3})$/i", $zipcode, $checkZip)) {
                                if ($checkZip[2] != ' ')
                                        $checkZip[2] = ' '; // Ensure that a space is between the two code segments.
                                $zipcode = $checkZip[1].$checkZip[2].$checkZip[3];
                        } else // Cause an error from incorrect length.
                                $zipcode = '';
                } else // No valid zip code matched.
                        $zipcode = '';
               
                if (!empty($zipcode))
                        $zipcode = strtoupper($zipcode); // Capitalize alphabetic characters for Canadian postal code.
                break;
        }
       
        return $zipcode;
}
?>


GM 06-14-2004 12:39 PM

Thanks for all your work NuAlpha... I'm gonna' try it now. :wink:

[UPDATE] Man... I hate to tell you this because I know you've put a lot of effort into this... it still won't catch P0H 1A (missing 1 letter... should be P0H 1A0)
Oh well, very valiant effort! I don't know how it could be done really???

NuAlpha 06-14-2004 01:01 PM

In the file "include/register.php", directly below...
Code:

$smarty->assign("error",$error);
...there should be:
Code:

if (@include('validate_zipcode.php')) {
        $b_zipcode = validate_zipcode($b_zipcode,$b_country);
        if (!empty($s_zipcode))
                $s_zipcode = validate_zipcode($s_zipcode,$s_country);
        else $s_zipcode = $b_zipcode;
}


Remove the "@" symbol before the "include" and then register a test customer to see if some problem shows up in your code. Note that PHP must be set to show errors for this to work.

GM 06-14-2004 01:44 PM

I got this error:
Code:

Warning: main(validate_zipcode.php) [function.main]: failed to create stream: No such file or directory in /home/www/goldmisers/include/register.php on line 116

Warning: main() [function.main]: Failed opening 'validate_zipcode.php' for inclusion (include_path='') in /home/www/goldmisers/include/register.php on line 116

Warning: Cannot modify header information - headers already sent by (output started at /home/www/goldmisers/include/register.php:116) in /home/www/goldmisers/include/func.php on line 197



All times are GMT -8. The time now is 04:01 PM.

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