I’d like the user to enter English letters only, not alphabets in Cyrillic, Arabic, other languages, etc. Is this possible in Gravity Forms? It would only be for two fields on the form; the rest of the form is OK for user to enter other scripts/alphabets.
Hi Jeremy. This Stack Overflow discussion has some possible solutions:
It looks like you would find a snippet that works for you, and add it to the form in an HTML field, and target your input IDs. Let us know if you need more information. Thank you.
Thank you, Chris! We decided on a Javascript snippet.
A team member also said this: "of course before the input, there would be a form action in a code = “/action_page.php”
Where would I place the Javascript snippet/code? In a (hidden) Gravity Forms HTML Field? And how do I target the input IDs? I’ll have to do this for two fields on Form ID 3: Field ID 4 and Field ID 5.
Yes, you can out the jQuery/JavaScript code into an HTML field you add to the form. It does not need to be hidden. The script won’t be visible on the page.
Share the code you plan on using, here, along with a link to the page where we can see the form, and we can help you with targeting the fields (normally it will be something like #input_22 as your jQuery selector.)
It looks like you want to add that JavaScript inline with the field? If so you can filter the markup when the form is rendered in order to add your JavaScript. You could use gform_field_content as the ‘time’ to add this JavaScript. You can use a PHP str_replace on something you know and replace with that thing you know, and your JavaScript. It would look something like this (this is for one field, field 43):
You can duplicate that code and change the first line with the form and field ID and then the name attribute to apply to any other field in the form. If you have any other questions, please let us know.
Excellent, I’m following you (understanding). So that code you sent (and variations and different targeted fields) would be placed in… functions.php? Or where? And do you recommend a separate add_filter( gform_field_content for each target/field (easy for me to figure out and view/modify) or one combined add_filter( gform_field_content (better tidy code)?
That is PHP code which can be added to your theme functions.php file, or you can use a plugin such as this one to keep the code separate from the theme: Code Snippets – WordPress plugin | WordPress.org
And I think you will need to use each filter individually, because the form ID and field ID are in the filter name.
Thank you so much, Chris, everything you’ve told me works great. We’re using the Code Snippets plugin too. I’ll now adapt the code snippets to target different fields, and I think I’m comfortable using/changing HTML ASCII in the PHP to enforce different things (letters, numbers, special characters, etc).