Service Area Input Validation (how to only allow certain zip codes access to hidden page?)

Hello kind people of Wix!

I have searched the google webs for a way to get this to work but to no avail. I know many Wix users would love to solve this as well so any help is greatly appreciated.

I would like my visitors to enter their zip code into a text box and when they click submit, their zip code gets checks against a pre-approved list. They will be directed to either page: “We service your area, book your appointment here” or “We’re sorry we don’t service your area”. My goal is to ensure that potential customers out of my service area won’t have access to the appointment scheduler (which is on a hidden page).

(here is another post that asks for the same solution)

Thank you for your input =]

I would simply set up a read-only collection/dataset containing all legitimate zip codes as text. Don’t connect the submit button to the dataset, just query the collection against the input zip code and the return will tell you if it’s legit. Maybe this is an over-simplification, but Velo, nee Corvid is great fun.

Hello Colin, thank you for the response. I’m afraid I don’t understand what you said :sweat_smile:. Could you maybe break this down in simpler terms?

If you’re not in a big hurry, I’ll try to set up a demo…

1 Like

@imobiletirechange

Just saw this post here. Perhaps it would also be helpful for the helping-user, to get some insight into your DB-structure. This makes coding much easier.

The more informations you provide, the better and faster answer you will get.

Assuming DB-structure stands for database, it would just be a list of zip codes. There is no more information to provide - the original post covers everything there is to the query. If you are looking for something specific please let me know.

1 Like

I would love a demo and I am in no hurry. Whatever information you can provide will help the community as a whole - thank you

@imobiletirechange Here, it’s not exactly what you are searchign for, but a simple example from a list of some of my very old works…

https://russian-dima.wixsite.com/meinewebsite/id-check

Perhaps it can be useful for you and Colin.

Here’s the collection sample - never mind the ‘site busy’ database name, it’s just one I play with for other projects.


Here’s a sample page -


And here’s the code that works in both preview and publish mode -

import wixData from 'wix-data';

$w.onReady(function() { //Ready page
    $w("#lock").onReady (() => { //ready dataset
  });
});

export function button13_click(event) {
    let zipQuery = $w('#inpZip').value; //Get user input Zip code
    wixData.query("SiteBusy")//This is just a collection I had hanging around and modified
    .eq ("z1", zipQuery)
    .find()
    .then( (results) => {
      if(results.items.length > 0) {
        let item0 = results.items[0];
        $w('#zipStatus').value = (zipQuery + " is Ok");
      } else {
        // handle case where no matching items found
          $w('#zipStatus').value = ("No matching items found");
      }
    })
    .catch( (err) => {
    let errorMsg = err;
    $w('#zipStatus').value = ("Error in query" + errorMsg);
  });
}


The dataset is set to read only mode and the collection permissions is set to ‘site content’. Hope this gets you on your way - the project was kinda fun.

1 Like