Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

ZipCode Validation Module

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #11  
Old 06-12-2004, 02:05 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

Don't worry about it! We're all guilty of asking newbie questions from time to time.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #12  
Old 06-12-2004, 02:29 PM
 
GM GM is offline
 

eXpert
  
Join Date: Mar 2004
Location: Canada
Posts: 293
 

Default

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 )
__________________
v. 4.0.14 (GM Style)
O.S. Linux
Build Your Own Diamond Ring
Reply With Quote
  #13  
Old 06-12-2004, 02:34 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

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.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #14  
Old 06-12-2004, 02:39 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

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.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #15  
Old 06-12-2004, 05:54 PM
 
GM GM is offline
 

eXpert
  
Join Date: Mar 2004
Location: Canada
Posts: 293
 

Default

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>
__________________
v. 4.0.14 (GM Style)
O.S. Linux
Build Your Own Diamond Ring
Reply With Quote
  #16  
Old 06-12-2004, 07:54 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

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?
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #17  
Old 06-14-2004, 07:09 AM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

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; } ?>
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #18  
Old 06-14-2004, 12:39 PM
 
GM GM is offline
 

eXpert
  
Join Date: Mar 2004
Location: Canada
Posts: 293
 

Default

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

[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???
__________________
v. 4.0.14 (GM Style)
O.S. Linux
Build Your Own Diamond Ring
Reply With Quote
  #19  
Old 06-14-2004, 01:01 PM
 
NuAlpha NuAlpha is offline
 

X-Adept
  
Join Date: Aug 2003
Location: US
Posts: 598
 

Default

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.
__________________
X-Cart Pro 4.5.5 Platinum
X-Payments 1.0.6
PHP 5.3.14
MySQL 5.1.68
Apache 2.2.23
Reply With Quote
  #20  
Old 06-14-2004, 01:44 PM
 
GM GM is offline
 

eXpert
  
Join Date: Mar 2004
Location: Canada
Posts: 293
 

Default

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
__________________
v. 4.0.14 (GM Style)
O.S. Linux
Build Your Own Diamond Ring
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:56 AM.

   

 
X-Cart forums © 2001-2020