Variable Special Codes - Problem with Conditional Logic

I have a form that has variable special codes that once they are entered correctly will give the customer one free ticket. I am trying to figure out how to get it to give me an “Invalid Code please try again” response if they don’t type in the correct code. The code will always end in “1017” the front part of the code could be anything and any length - such as “bakery1017” or “restaurant1017” - so my conditional logic should be something like - does not end with - instead of ends with. If it takes javascript or php to fix it … I want to be able to insert the code in an HTML block so I can add this to multiple forms. Anyone have any ideas?
See https://temporarysite10.com/free-ticket-registration/ - if you type “bakery1017” in the FREE Code block you get back the correct response - but the “invalid” message is there all the time even when the field is blank.

Hello JuDonP. There is no Gravity Forms validation code you can add to an HTML block that will work for this. That would require some type of JavaScript validation, which is not currently a feature of Gravity Forms. You can do this with conditional logic though, right in the form settings. You can use the conditional logic setting on a Section field so that the Section is not visible until a matching code is entered. The section can contain the rest of the fields required in the form, and they will all be hidden by that conditional logic rule.

Before the section field, you can have an HTML field using conditional logic, to show an error message when the code does not match you rules. The rule would be ‘ends with’ and your string 1017.

One downside to that is the the conditional logic rule is present in the source of the page. If someone were curious, they could check the source and find out the conditional logic rule relies on the code ending with 1017.

The best method is probably to use the gform_field_validation filter to check what code was submitted to you, and if the last 4 digits were not 1017, return a validation error.

If you have any other questions, please let us know.

Thank you very much … this truly helps. I didn’t realize the fields under the section field were hidden into the valid code is entered … this is great info.
Thank you for taking the time to answer! I appreciate it.

I love Gravity Forms!

Thanks,
Judi Privett
StudioG360

Thank you Judi. Yes, the fields in a section will be hidden by the conditional logic rules on the section. They won’t need their own rules if you want them to obey the conditional logic of the section. The section will continue until the end of the form, or the next section or page break field. If you have any other questions, please let us know.

© 2008 - 2021. Gravity Forms is a project by Rocketgenius Inc.