I'm trying to set up a Formidable Form where users enter their ZIP code, and based on their entry, they get a message letting them know if they are inside or outside our service area.
I service a large area so my list of ZIPs is pretty long. It seems like a dropdown isn't the best for such a long list, what do you all think?
The only other way I can think of doing this right now is conditional logic, but I'd have to set one up for each ZIP, which seems inefficient. Is there a better way to do it? What I'd love is to be able to paste my list somewhere and have Formidable check against it. Like, only allow this field to accept ZIP codes from this list.
I would use Ajax to perform a real time lookup and skip the emails altogether.
thanks. i put this in my custom HTML "before" field. is this what you meant? this code works in that it pops up a message, but it still submits the form...
document.addEventListener("DOMContentLoaded", function () {
const allowedZips = [
"19311", "19320", "19330", "19333", "19335", "19341", "19342", "19348", "19350",
"19351", "19352", "19355", "19360", "19362", "19363", "19366", "19372", "19374",
"19375", "19380", "19381", "19382", "19390", "19395", "19010", "19014", "19063",
"19065", "19073", "19087", "19317", "19319", "19331", "19373", "19707", "19711",
"19807", "19808", "19803", "19810"
];
const zipField = document.querySelector('input[name="item_meta[209]"]'); // Updated field name
const form = zipField.closest("form");
form.addEventListener("submit", function (e) {
if (!allowedZips.includes(zipField.value.trim())) {
e.preventDefault();
alert("Sorry, it looks like you may be outside our service area. Please feel free to try a different ZIP or call us.");
}
});
});
That's not what I had in mind at all. I suggested AJAX and that's not it. I would use jQuery and definitely not use const when creating a value from a field variable. When a const is initialized, it cannot be changed. You are declaring it in the content loaded event. zipField will be populated when the page is loaded not after data has been input.
It's pretty clear from this approach that you may need to consult with a developer. What you want to do is more than can be explained or taught in a community volunteer thread. If you need a consult, please visit https://formidable-masterminds.com/developers-directory/.
Please login or Register to submit your answer