I am working for a home loans company in Canada, but basically we don’t service very small towns.
I want to create some conditional logic that will show a rejection message if the person has a input a small town as their address. I can probably make a very long conditional that includes every smaller town, but not sure if this is the best way to do things.
Hi Jonathan. How are you going to maintain the information that determines if you service them or not? Is that in a file, or a database, or an external service? How many towns are in the Yes list and how many are in the No list? There are several ways to approach this. You will most likely be looking at using gform_field_validation:
OK. I think in that case I recommend using gform_field_validation. You can read that file (either CSV or JSON) using PHP and this filter:
Then you can return a validation error (message if they are on the No list) or let them pass to the next page if they are on the Yes list. There is a possibility they are not on either list, and I am not sure what you want to return to them in that case.
We covered doing something like that here:
Take a look at those topics and let us know if you need a nudge in the right direction.
Yes, you could populate fields in the form with additional information, and then use conditional logic to route them somewhere else, rather than returning an error. I think I would use gform_pre_submission in that case, so that you can retrieve the data from the data file, and then populate hidden fields in the form with data you retrieved. Then you can show one confirmation or another (based on the data you retrieved) using conditional logic. gform_field_validation would be used to stop them from submitting the form and return an error, which it does not sound like you want.
Once you have the data accessible to Populate Anything, you could create a Hidden field whose value is dynamically populated based on the value of another field. You could label this field “Is small town?” When the user enters their town, you can filter the value of this Hidden field to return a true or false depending on whether the town name exists in your list of small towns.
Here’s an example of what that field might look like if you use a Gravity Form to store your small town list:
Thanks for your input here.