Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2012
    Location
    Kochi,Kerala
    Posts
    58
    Plugin Contributions
    4

    Idea or Suggestion Converting osc contribution Post code Validation

    Can any one tell me whats wrong with this function?, I am a Newbie in PHP

    Function in "\includes\functions\functions_general.php" to Check
    PHP Code:
    // VALIDATE POSTCODE START
    function tep_validate_postcode($country_id$postcode)
        {
        
    $postval =$db->Execute"select countries_postal_validation from countries where countries_id = '" . (int)$country_id "' limit 1");
        
            if (
    zen_not_null($postval->fields['countries_postal_validation']))
            {
            return (
    preg_match($postval->fields['countries_postal_validation'], $postcode));
            }
        else return 
    true;
        }
    // VALIDATE POSTCODE END 
    Checking of entry in "\includes\modules\pages\address_book_process\header_php.php"

    PHP Code:
    if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
        
    $error true;
        
    $messageStack->add('addressbook'ENTRY_POST_CODE_ERROR);
      }
    // VALIDATE POSTCODE START
        
    if (tep_validate_postcode($country$postcode) == false)
            {
            
    $error true;
            
    $messageStack->add('addressbook'ENTRY_POST_CODE_VALID_ERROR);
            }
    // VALIDATE POSTCODE END 
    Thanks in Advance

    Vinod

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Converting osc contribution Post code Validation

    You can't access the $db variable from inside a function if you don't declare it as a global first.

    Code:
    function name_of_function()
      {
        global $db;
        // rest of code which uses $db goes here
      }
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jul 2012
    Location
    Kochi,Kerala
    Posts
    58
    Plugin Contributions
    4

    Default Re: Converting osc contribution Post code Validation

    Quote Originally Posted by DrByte View Post
    You can't access the $db variable from inside a function if you don't declare it as a global first.

    Code:
    function name_of_function()
      {
        global $db;
        // rest of code which uses $db goes here
      }
    Thank you DrByte,

    gotcha, I just forgot

    Uploading the contribution, will be available to download after authorization

  4. #4
    Join Date
    Jan 2007
    Location
    Australia
    Posts
    6,167
    Plugin Contributions
    7

    Default Re: Converting osc contribution Post code Validation

    Quote Originally Posted by vkd1980 View Post
    Can any one tell me whats wrong with this function?, I am a Newbie in PHP
    I note that DrByte has provided the solution, but I do have another very minor suggestion of my own.

    Quote Originally Posted by vkd1980 View Post
    function tep_validate_postcode($country_id, $postcode)
    My suggestion is to change "tep_validate_postcode" to "zen_validate_postcode" (in every place it is referenced).

    Although this will make NO DIFFERENCE to functionality, the change will serve several purposes.
    Firstly it will make the code follow the zencart coding standards.
    Secondly it will obfuscate the fact that this was a direct port from an OsCommerce module
    Thirdly, in the odd chance you ever need to perform a global search for zencart functions using the 'zen_' prefix it will assure that your function will be found along with all the other zen_ functions.

    As I say, it's not a big deal, and it's not worth rushing out to make the change. It's just something to keep in mind and possibly implement if/when you need to make other changes.

    Cheers
    Rod

  5. #5
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Converting osc contribution Post code Validation

    or better yet, maybe "vkd_" would be better than "zen_" since it's not really a Zen Cart function.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  6. #6
    Join Date
    Jul 2012
    Location
    Kochi,Kerala
    Posts
    58
    Plugin Contributions
    4

    Default Re: Converting osc contribution Post code Validation

    Quote Originally Posted by DrByte View Post
    or better yet, maybe "vkd_" would be better than "zen_" since it's not really a Zen Cart function.
    Quote Originally Posted by RodG View Post
    My suggestion is to change "tep_validate_postcode" to "zen_validate_postcode" (in every place it is referenced).
    Me Also Agree,

    I will Change the function Name to "zen_validate_postcode" and will upload fresh file soon,

    Dear Moderator,

    Please reject the current file uploaded

    Vinod

 

 

Similar Threads

  1. v151 Old OSC db Backup Need help converting
    By jbginz in forum General Questions
    Replies: 1
    Last Post: 26 Aug 2013, 08:46 PM
  2. Converting Header from OSC to Zen
    By msmith1111 in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 15 Nov 2008, 04:49 AM
  3. Help converting OSC SQL code to Zencart
    By ozetrade in forum Built-in Shipping and Payment Modules
    Replies: 10
    Last Post: 4 Feb 2008, 09:27 PM
  4. Converting from osC to Zen
    By Therose in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 14 Jan 2008, 02:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR