Formidable Forms Save Custom PHP Value in Hidden Field

When the basic WordPress contact form plugins just don’t cut it, we look to more advanced form builders like Formidable Forms or Caldera Forms to do the job. And most of the time, it would be very easy, but this time, we faced a small challenge.

In this article, we go through how to save a user’s WordPress locale value into Formidable Forms hidden fields so that you can use the value for processing after user submit forms. To start off, I’ll share more about the specific challenge we had. And then I’ll get into how we solved it.

The Challenge

For this particular requirement, we needed to build a contact form which required some simple logic, simple calculations, and email notifications in different language based on the locale which user was browsing in.

We hit a challenge at the part where we had to detect the locale. The easy way would be to have a field in the form for user to select their current language, so that they can receive an email summary notification in that language. But this just doesn’t make much sense since they are already browsing the site in their desired language; asking users to select their desired language in a form is simply bad user experience.

So the right thing to do would be to use a hidden field to hold the current locale which user was browsing in. It’s easy to create a hidden field, but where or how to get that value of current locale?

How We Saved a Custom PHP Value in a Formidable Forms Hidden Field

1) WordPress provides a hook to get the locale.
It’s as simple as this.


Ok, but we can’t just place PHP code as the default value in Formidable Forms.

2) Formidable Forms support using shortcode as the default value.
So now we needed to create a shortcode to get the locale. This code can be placed in the functions.php file or using a code snippets plugin.

add_shortcode('get_current_language', 'custom_get_language');
function custom_get_language() {
return get_locale();

3) So then we can use the shortcode [custom_get_language] as the default value in the hidden field.

4) And to trigger email notifications in different languages, we simply created different email actions based on the condition of locale value submitted in the hidden field.

And the good part of this is, this method with Formidable Forms can be used not just for saving the locale, but any other WordPress value or PHP value. It’s all in the shortcode.

And that’s a wrap, many hours of our research and development shared in one simple 4 step summary.

Formidable Forms is a plug-in that comes built-in with 30 Field Types, drag and drop customisation of layout, conditional logic, calculations, form validations, email notifications and the database of all your form entries in WordPress.

Any questions? Feel free to leave a quick comment below.

I’ll be around to reply comments and answer questions.


Formidable Forms Save Custom PHP Value in Hidden Field 1

Smmile is a Digital Marketing Agency in Singapore with over 10 years of experience in the industry.