Required "code" field to submit form successfully

Is there a way to require a specific string to be entered in a field, i.e.: alphanumeric, for the form to be able to submit successfully?


You could do that pretty simply with conditional logic on the Submit button (the setting is on the Form Settings page.) Add a single line text field to the form to accept your code. Make that field required. Then, on the Submit button, set the conditional logic to SHOW the button only when the field you added matches WHATEVER you want your code to be.

The downside of that is that the code is visible in the source of the page, if anyone is inclined to look.

Another way to do it, where the code is never visible, is to use the gform_field_validation filter. After the form is submitted with the code in that field, you check that field to see if the code entered matches the code you require. If not, you return a validation error and the form cannot be submitted.

It would look something like this:

Instead of comparing the entered value to see if it is less than 10, you would simply see if it does not match whatever code you want it to match.


We are using dynamic poplulation in order to use a few GFs for our event registration system. I know how to dynamically populate the Text Field with a code. Is there a way to dynamically pass the code to the conditional logic for the Summit Button?

Can you explain more what you mean? Normally, you would set the conditional logic rules on the submit button in the form builder. Then when you dynamically populate the text field, that value would be compared to the conditional logic rule for the submit button. What is the reason that does not work for you?

Say we have 3 events: eventA, eventB, and eventC. Each is prepaid, so nobody pays individually. I need a unique code for each event. E.g. eventA100p (100% off). When people register they use their code. What Iā€™d need to do using this technique is dynamically pass the code to the logic for the submit button.

Alternatively, I can create a coupon code for each event. An extra step, but not a lot of work.