V4.1.x Finishing Up - Users State and City Auto populated based on ZIP Code entered US Only

Discussion in 'Modules / Plugins / Modifications' started by TheTechGuru, Mar 21, 2011.

  1. TheTechGuru Customer

    Just wanted to see if there was any interest in a modification I am making for US based Classified Sites (International May Be Coming Soon depending on interest, since I dont really need it).

    I got tired of the idea that any user can come in and populate my database with a fake city or misspelled (Pheonix, Phoenix, etc) city upon signup, which could in turn make the city dropdown on the search page and city variables throughout the site look very unprofessional.

    I just finished up a modification that will populate the city, state, longitude, latitude, and even county based on the zip code they enter for any US state. The modification consists of a database with over 45,000 entries, a php script and minor modifications to the signup template.

    Now its just on to testing. I wont really be using it for signup because I am focusing on using it for listings, which will allow members to submit ads that might be in different locations (real estate etc) instead of forcing every ad location to be their signup location.

    But the signup part is done for those that are interested.

    Im gonna test it for a few days, and make any changes I may deem important or adds functionality.

    If anyone is interested let me know, I will charge a really fair price for the time its taking me, since I was coding it anyways. nothing more, nothing less.

    It makes no changes to the existing php files as of right now. Will work for 4.0.x and up.
  2. TheTechGuru Customer

    Finishing up a Canadian Version Now.

    Just to be clear, this will auto populate a users city, state (in this case province) etc, based off a simple input of a zip code or postal code. And will populate those said fields on the fly, dynamically.


    The beauty of it is, you can easliy disable state/province, country, city etc fields, so they can see the data being populated in the disabled text fields, but they can not change it. The only way to change it is by changing the zip/postal code.

    And if for some reason they leave the postal code empty, the standard validation kicks in and will not let them register until they have submitted that info.


    Both My US and Canadian Databases are fairly extensive, so everything should be covered. Now all thats left to do is plan for a situation in the future of zip code changes, or city changes. This will be done in a pretty cool way, and will speak about it later.

    longitude and latitude is also included each zip/postal/city, so if someone wanted to tie in google maps or some sort of geo function in the future, it will be a snap.
  3. TheTechGuru Customer

    No changes to any existing php files...

    First Version is done (US), just looking for a live site to allow people to demo it. The good news is, its completely compatible with the search by zip code mod offered on classifiedmods just in case anyone has it installed.

    Basically, once a user inputs their zip, it will automatically fill in the respective city state and country as they type.

    The database this uses is bigger by about 10,000 more entries though than the one supplied with the search by zip code mod. (My Zip Database hase roughly 47,000 entries), so those that have the search by zip code mod, might want to consider looking into this modification to get this bigger database which will allow more exact radius searches.

    The good news is that I am working on a Canadian Version, and a European Version tonight, and they will all work together. You wont be stuck with just US, you can utilize them all at the same time.

    If you want a way to keep people from misspelling their city, or entering in jibberish which will make your city drop down in search look terrible, than you should check on this post, and I will update it as soon as I find someone willing to host it for demonstration.

    For those of you that want to allow someone to enter input, in the unlikely case that their city isnt found after they input their zip, good news Im working on something that will allow them just to put in the next major city closest to them, and at the same time, request that their location be put into the system. After you approve their selection, you will be able to submit it from and admin type panel, and their info will be updated.

    Stay Tuned for more...
  4. I am very interested! Keep us updated!
  5. TheTechGuru Customer

    Just finished with the canadian version.

    Is there anyone from Canada here? Or Know about the amount of postal codes? My database of postal codes says 700,000 entries? that seems rather large.

    Its working fast and fine, but I think Im gonna do a bit of research on the database I have, as I know absolutely nothing about Canada, other than they are above us.
  6. Mike-N-Tosh Developer & Moderator

    There are 1,620 postal codes for Canada. (I sell the Postal Codes Module for almost every country in the world)
  7. Mike-N-Tosh Developer & Moderator

    I need to clarify that answer, there are 1,620 Forward Sortation Area Codes (FSA) If you also use the Location Delivery Unit (LSU) then it goes up substantially. The LSU is like the +4 US zip code extension. Many countries have a similar type extension that may or not be relevant to doing this type of development. Most times it is NOT relevant.
  8. TheTechGuru Customer

    Yeah, thats a pretty big database, I may have to look for a condensed version. Not sure if it can be done, as this is pulled from the database by postal code, and a condensed version would obviously be missing postal codes.

    the wikipedia says "This scheme allows for a maximum 3,600 FSAs: with 2,000 possible LDUs in each FSA, there is a theoretical maximum of 7.2 million codes"

    Why in the world would they ever need to use that many?? Holy Cow!

    If they ever reach 7 million combinations, I would think that would be more of burden, than helping as the codes are intended to do.

    The database I have does indeed have 700,000 records, I see a lot of provinces and cities being duplicated, however I dont see any postal codes duplicated. If I want to truly account for every postal code possible, I may have to keep it as is.

    Any tips Mike-N-Tosh?
  9. EnergyFreak Customer

    I am a canadian user and I am also very intrerested in this module. Since there are six digits/letters in a postal code, (ex: H2H 2H2) there will be more possibilities then US zip code which is 5 I believe. (ex: 90210).

    I replaced the state fucntion to become cities and the country function to become provinces (to avoid gibberish). But with this mod I would not have to do this, even better!

    I am running a test website right now for a V2 of my template, I could probably use it as a demo site for a while and test it for you.
  10. Mike-N-Tosh Developer & Moderator

    My advice in correlation of what you are doing is that you don't need anything but the FSA's to simply populate cities. Don't know what your DB is using as a "postal code" field. It sounds like (since you have 700K) it is using a full FSA-LSU as the field.

    What you are reading in Wikipedia is the theoretical math applying the coding system as to the theoretical number of unique full codes that are possible, NOT what is actual in use. A mathematical equation. Compare it to say IP addresses like IPv4 which they just doled out the last of! IPv6 allows many more addresses. Same thing. A mathematical equation that gives you a huger number.

    So, modify your existing db and extract just the FSA portion of the code. That will still be unique in your use to populate the city. The FSA is alphanumeric and is the first 3 characters. (e.g. "XDA", "TDL", "K2K", etc.). My guess is that will then bring your new db down to 1,620 postal codes give or take a couple.
  11. TheTechGuru Customer



    Okay, that would be great.

    The Canadian version is ready, how soon can we start?

    Like I said before though, the Canadian database is huge, you will have to upload it in separate files that I will premake for you, just import them through your phpmyadmin.

    If you need the US version, let me know, they work together if needed, but I need a day to look everything over, make sure they play nice together and button everything up to handle two countries.

    You can have the mod, for hosting it for me. Fair Trade?

    BTW, if I find a way to condense the database, without losing any functionality, I will let you know asap, might not be much need though, as it cycles pretty fast as it is. The US version is obviously faster, its only 45,000 entries.
  12. TheTechGuru Customer

    I was thinking about that, the problem Im running into is that some fsa's have multiple cities. A0N for example ranges from McCallum to Grey River. And the postal codes themselves have both the FSA's and LSU's in the same field. Thats the problem im having, I may be able to break them up into separate fields and just delete the new LSU field created, but then im still stuck with the multiple city per FSA issue.

    Im sure there is a solution, any condensing will help.

    Lets just say that Im glad that as of right now its just a mathematical theory with the postal codes... 700k is enough in my book. Beats saying "Hey take this to the house by the red mailbox on the street by the dead tree."

    Anyways, I may be able to follow your lead and delete the entries that are duplicate in city and province but diff LSU, that should be a good start. I will just have to tweak the code to look for just FSA unless a LSU is present in both the input and database. im getting a headache just thinking about it...

    To those reading this, the mod still works great without doing this, this is just the tweaker in me that wants to condense it to the smallest form without losing any functionality.
  13. EnergyFreak Customer

    I have tried the module and it is quite the thing, when entering a zip/postal code it will automatically grab it from the database and fill in the city and state. A must have for a classifieds site.
  14. Mike-N-Tosh Developer & Moderator

    If it were me, I would isolate the FSA's that do have multiple cities. Then on the rest get rid of all the duplicates FSA's that point to the same city. In your search function, bust out the postal code into two variables, $fsa and $lsu. Use the $fsa for the query, then put an if statement. if you have more than 1 result, then either run the query on the found set using the LSU or rerun the whole query using both $fsa AND $lsu.

    It just seems that having a huge db table with a busy site on a shared host (that probably also has disk space restrictions too) may run into trouble. You could probably bring your db table down to less than 2,000 rows.
  15. TheTechGuru Customer

    Right On Mike-N-Tosh,

    Thats exactly what im going to attempt, thank you for the advice. Im not gonna feel right until I bring this size down. Darn Canadians.. kidding... kidding

    U should just let me email you the database or send a link to grab it compressed and let me pay you to condense it.
  16. TheTechGuru Customer

    Just to give a small update, Im working on bringing down the database for Canada, its a lot of data, so it will take a day or two, unless I get some sort of help. Not a big deal, I just want to make sure it account for as many postal codes as possible without needing a huge Database.

    Perhaps when Im finished someone can take it and make it an actual module, which will in turn pretty much also teach me how to make a module by looking at what they do. I am extremely short on time or I would learn from scratch.

    Last thing, I am also adding a function right now that accounts for more than one location matching the zip or postal code a user may enter.

    I expected the modification to be finished and have a version 1 out, but other variables popped up that I didnt take into account, for instance my site will only allow members from the US and Canada to sign up to begin with, however some of you have a broader audience, and there needs to be a function to account for a user living in a country other than just the 2 I am starting with.

    Stay tuned, and I will update this post with new info.

    I am working with another member right now to get the Canadian an US version up for demo on a demo site.
  17. TheTechGuru Customer

Share This Page