Dont Know Zip Code
From PikaDocs
I recently remarked on the Pika users list:
I am told that we sometimes (less than once a day, but at least a few times a week) have clients call who don't know their zip code. It hasn't been a problem in our current CMS which can do zip code lookups either way: lookup zip if have city and state or lookup city and state if have zip. (It knows enough zip codes to do this for Vermont zip codes only).
Pika of course can lookup city and state based on zip code (I believe this was added in one of the more recent versions), but not the other way around.
Does anyone else have experience with the problem of a client calling and not knowing their zip code, and if so, how have you solved it?
This page deals with possible solutions to the problem.
Fix version 1.0
Some interesting solutions came back from the list. Aaron and Brian L. created this nifty bit of code:
<a href="http://zip4.usps.com/zip4/welcome.jsp?address2=%%[address]%% &address1=%%[address2]%%&city=%%[city]%%&state=%%[state]%%" title="Click to lookup zip code" target="_blank">Zip Code</a>
To break this down a bit, the link target is a post office website which lets you put in address, city, state, and zip, then submit a form and get the zip code. The link is constructed by PHP at the time the contact screen is created so those template tags like %%[address]%% are filled in by Pika. The title attribute is explained quite well here. The target="_blank" tells the browser to open a new window so the user doesn't lose their place in Pika.
So you wrap this link around the text Zip Code in your subtemplates/contact_full.html. The user can now click on those words and look up the zip code in a separate window, returning to Pika and pasting in the determined zip code.
Fix version 2.0
Since then, I've discovered some shortcomings in the first solution and am testing something a bit mroe complicated. The problem in a nutshell is that the zip code link is constructed by PHP not javascript. Say that a user is editing a person who was a client a couple years ago but has since moved and is calling for new help. If you change the client's address, city, and state, and erase their zip code, and do the zip code lookup, it will look up their old address rather than their new address. This is because you haven't clicked save yet.
So I'm trying some alternative code, that is more complicated, but will scrape the address, city, and state off of the current form rather than relying on what was last saved.
The link now looks like this:
<!-- New zip code lookup Andrew Cameron 2006/3/21 Note: returning false after calling lookup_zip(); will stop the default action of the href which is to open the link referenced from: http://www.yourhtmlsource.com/javascript/popupwindows.html --> <a onclick="lookup_zip();return false;" target="blank" href="http://zip4.usps.com/zip4/welcome.jsp">Zip Code</a>,
Now when you click the link, it calls a javascript function named lookup_zip() which is explained below. After calling that function the javascript returns false. This prevents the normal action of the href. If the user's browser doesn't have javascript enabled, the onClick event is never triggered, and instead the browser will open the post office website in a new window (different from version 1.0 however in that none of the fields will be filled out). This is a fallback safeguard for browsers w/o javascript enabled (although, is anyone using Pika that way? So much else would be broken.)
Next, a new javascript function needs to be added to the javascript section at the bottom of the file:
// new function Andrew Cameron 2006/3/21
function lookup_zip()
{
url = "http://zip4.usps.com/zip4/welcome.jsp?address2=" + document.fc.address.value + "&address1=" + document.fc.address2.value;
url += "&city=" + document.fc.city.value + "&state=" + document.fc.state.value;
ziplookup=window.open(url,'ziplookup');
ziplookup.focus();
return;
}
This function scrapes the current value of those fields off of the screen, whether or not the page has been saved, and then calls the post office website and fills in the values.
Wishlist
One other note: in my ideal world, when the user clicks the Zip Code link, that action would also save the form at the same time it opens up the new window for zip code lookup. I tried adding a call to document.fc.submit() which I found works fine in Firefox, but in IE 6 the focus goes back to Pika instead of the zip code lookup window, thus confusing the user. So I left this out for now. Don't know if this is a bug or feature in IE.
original entry By Andrew Cameron
Legal Services Lawline of Vermont (http://www.lawlinevt.org/) and Vermont Legal Aid (http://www.vtlegalaid.org/)
