From 454d43f1d341623f71e0cb26d7af9a299372dd79 Mon Sep 17 00:00:00 2001
From: James Sinkiewicz <james@jscs.com>
Date: Fri, 25 May 2012 10:44:34 -0700
Subject: [PATCH] Fixed zipcode issue

---
 .../location_views_handler_filter_proximity.inc    |   29 ++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/handlers/location_views_handler_filter_proximity.inc b/handlers/location_views_handler_filter_proximity.inc
index 5a38acc..8286edb 100644
--- a/handlers/location_views_handler_filter_proximity.inc
+++ b/handlers/location_views_handler_filter_proximity.inc
@@ -4,6 +4,35 @@
  * General proximity filter for location latitude/longitude.
  */
 class location_views_handler_filter_proximity extends views_handler_filter {
+  /*
+   * Validate the options form.
+   * This section added to test http://drupal.org/node/1175452#comment-4615850
+   */
+  function exposed_validate($form, &$form_state) {
+    $origin = $this->options['origin'];
+    $key = $this->options['expose']['identifier'];
+
+    //check than the postal code is in DB
+    if (!empty($form[$key]['postal_code']["#value"])) {
+      $result = db_query("SELECT zip FROM {zipcodes} WHERE zip = :zip LIMIT 1", array(":zip" => $form[$key]['postal_code']["#value"]));
+      if ($result->rowCount() == 0) {
+        form_set_error("$key][postal_code", t("You have entered an invalid Postal Code."));
+      }
+    }
+
+    //check that distance is a number
+    if (!empty($form[$key]['search_distance']["#value"])) {
+      if (!is_numeric($form[$key]['search_distance']["#value"])) {
+        form_set_error("$key][search_distance", t("Distance has to be a number"));
+      }
+    }
+    else {
+      if ($form[$key]['search_distance']["#value"] == ''){
+        form_set_error("$key][search_distance", t("You must enter a Distance"));
+      };
+    }
+  }
+  
   // This is always multiple, because we can have distance, units etc.
   var $always_multiple = TRUE;
