This plugin allows multilingual contact form 7 management using the polylang plugin.
NOTE v2 is now an extension of the CF7 Smart Grid-layout plugin. You need to install it to use this plugin. Why is this? You can read this thread, and this post.
This plugin allows multilingual contact form 7 management using the polylang plugin. As of version 2.0 of this plugin, it is now developed as an extension of the CF7 Smart Grid-layout plugin. All 3 plugins, Polylang, CF7 Smart Grid-layout and Contact Form 7 need to be installed prior to installing this plugin. Works with multisite installations too.
this plugin introduces form keys (which you can modify in the CF7 admin table). Keys are unique for each form, allowing you identify a form my its key rather than an ID. Why is this priceless? IDs changes from one server to the next because they are the custom post ID attributed by the WordPress installation, and therefore you develop your form in a local machine only to find out that the IDs are different when you move your form to your production server. To overcome this problem, we suggest you use a form key along with this plugin’s contact form shortcode, [cf7-form key="contact-us"]
. Don’t worry your old contact form 7 shortcodes will still work too, behind the scenes we simply map the key to the ID and call the regular contact form 7 shortcode.
Similarly you can use any translated form shortcode, and the plugin will make sure the right language is loaded.
Please follow the Installation instructions carefully, especially the part about saving your Polylang settings after you have activated this plugin.
English subtitled video on youtube, Spanish & French subtitles available in the caption settings.
CF7 Polylang Module – this plugin allows you to create forms in different languages for a multi-language website. The plugin requires the Polylang plugin to be installed in order to manage translations.
CF7 Multi-slide Module – this plugin allows you to build a multi-step form using a slider. Each slide has cf7 form which are linked together and submitted as a single form.
Post My CF7 Form – this plugin allows you to save you cf7 form submissions to a custom post, map your fields to meta fields or taxonomy. It also allows you to pre-fill fields before your form is displayed.
CF7 Google Map – allows google maps to be inserted into a Contact Form 7. Unlike other plugins, this one allows map settings to be done at the form level, enabling diverse maps to be configured for each forms.
Smart Grid-Layout Design for CF7 – allows responsive grid layout Contact Form 7 form designs, enabling modular designs of complex forms, and rich inter-linking of your CMS data with taxonomy/posts populated dynamic dropdown fields.
Gérard Mathiuet for providing a fix for PolylangPro.
Peter J. Herrel for improving the language folder management.
Didier (@swissspaceboy) for pointing out an issue with the CF7 Special Mail tag [_site_url]
.
This plugin, in itself, does not:
If you don't see the polylang links in your contact table list, head to the Polylang settings and save the existing post content to the default language. (Step 6 in the installation instructions)
Contact form table list with Polylang language columns, a dropdown of available languages next to the 'Add New' button allows you to create new forms in any language, note also the portable cf7 shortcodes.
Creating a new translation form, with polylang language metabox options.
Ensure you enable translations for Contact Forms in your Polyland settings.
If you found that you installed the plugin correctly and are able to manage your forms using the polylang language columns, then it is likely that the language your have selected does not have a translation for the Contact Form 7. You can visit the following translation project page to see the status of the translation CF7 for your language.
If you have checked the above linked page and are able to find your language, then you can download your language translation pack manually. It is possible that there is mismatch between the local code used by Polylang and that assigned to your language pack.
Open the translation page for your specific language (click on the language row in this table). This will open the locale specific page that you have selected, then click on the ‘Stable’ link in the table. You should now see a page with a table that show the different translations, scroll to the bottom of the page and selected the Export format from the 2nd dropdown to ‘Machine Object .mo’, then click the Export link. This will download a zip flie. Extract the content of this file in the wp-content/languages/plugins/contact-form-7/
folder (create it if it does not exists, this folder is never updated by plugin updates). Rename file name so that the locale of the file matches the locale of your language as defined by Polylang. When you create a new form in your language you will find the polylang locale code in the url attributes of your browser address bar. So if your locale is tk_TK, and you have dowloaded and extracted a file called contact-form-7-tk.mo, rename it to contact-form-7-tk_TK.mo. This will ensure the correct file is picked.
This is because the translation in your language have not be completed. You can help the community by completing the translation online. You will need to sign up for an account if you haven’t got one already and login. You can also complete the translation on your computer by following the above procedure to download the current status of your language translation. Instead of the ‘Machine Object .mo’ format, select the ‘Portable Object .po’ format. Extract the file from the zip archive your download and edit the file using the PoEdit(or). You can then save your translation in the ‘Machine Object format’ and follow the remaining instructions above to make sure your new translation file is picked up by the plugin.
In order to ensure the correct translation is shown in your template page, you need to make sure you get the translated id $trans_form_id
in your do_shortcode
function call,
do_shortcode([contact_form_7 id="{$trans_form_id}"]);
You have Polylang setup using a default language and a set of additional languages. When Polylang translates a custom post (such as the wpcf7 post), it keeps track of all translations using the post ID, by pairing the primary language post ID with its corresponding translated post IDs which is what the CF7 Polylang Extension does for you.
So you need to search your translation using the primary language post ID, to do this you need to make use of the Polylang functions,
$form_id = 252; //assuming this is your default language form ID $default_lang = pll_default_language('slug'); $current_lang = pll_current_language('slug); //the current language your page is being viewed as if($current_lang != $default_lang){ $form_id = pll_get_post($form_id, $current_lang); if(empty($form_id)){ //if a translation does not exists $form_id = 252; //show the default form } } //display your form echo do_shortcode('[contact-form-7 id=”'.$form_id.'″]');
Polylang only filters links and provides the current language function pll_current_language()
for the front-end requests. Submissions are handled using admin hooks by the CF7 plugin and these do not have access to the pll functions. To overcome this limitation, v2.3 of this plugin introduced the _wpcf7_lang
hidden variable which is automatically submitted. So you can find out the current language of the submission using the $_POST['_wpcf7_lang']
value.
The cf7 plugin provides a special mail tag [_site_url]
which prints the site url. However, this is not one of the filtered polylang links. Therefore as of v2.3 this plugin now has the [_home_url]
mail tag that you an use in your mail body and which will show the home url of site from which it was submitted from.
Alternatively, you could also construct your own special mail tag, such as [_lang]
using the follwoing code in your functions.php file,
add_filter( 'wpcf7_special_mail_tags','my_cf7_mail_tag', 10,3); function my_cf7_mail_tag($output, $name, $html ) { if ( '_lang' == $name ) { $filter = $html ? 'display' : 'raw'; $output = $_POST['_wpcf7_lang']; } return $output; }
If you have a plugin which has specific translation strings used in CF7 forms, you need to tell the CF7 Polylang plugin to load the resources for the required locale. To do this use the following filter hook,
add_filter('cf7pll_load_plugin_translation_resource', 'add_translation_resource'); function add_translation_resource($plugin_translation){ //the $plugin_translation is an array into which you need to add your plugin slug and version number. $plugin_translation['my-plugin-slug']=$version. return $plugin_translation; }
this filter should be used by plugin developers to ensure their plugin translation resources are loaded.