Home » Documentation » Developers Information » Translation for texts by other plugins and themes » How to use Contact Form 7 in multilingual websites

How to use Contact Form 7 in multilingual websites

Update: the author of contact form has removed the code from his plugin which supports this functionality. If you want to have it back, we recommend contacting CF7 author and requesting to add it again.

Starting with version 2.0, Contact Form 7 can create multilingual contact form using the WPML plugin.

Checklist for getting started:

  • Install and enable WPML.
  • Install Contact Form 7 v2.0 (or a later version) and activate it.

(the order for these operations can be reversed as well)

Open Contact Form 7′s admin page and begin to editing a contact form.

Making a contact form multilingual

There are three parts of Contact Form 7 which WPML can make multilingual:

  1. Contact form field names
  2. Text outside of field labels
  3. Feedback to visitors (what they get after submitting a form)

There are different procedures for translating each of the items above.

Making field names multilingual

To make form fields multilingual, add the icl attribute to the tag.

For example, have a look at the following tag (country name for the contact form):

[select your-country "China" "India" "San Marino"]

To make it multilingual, visitors would need to see the different countries in their languages. Insert icl before the list of options.

[select your-country icl "China" "India" "San Marino"]

The process about is fine. You can also use the following alternative syntax which also specify the text context. For following format tells the translation system that we’re translating a field called "country-names". It makes the translation easier as when we translate the strings, we know what we’re translating. To use it, insert icl and then the field name (which is not translated itself).

[select your-country icl:country-names "China" "India" "San Marino"]

Translating text besides field names

In order to change make text that’s outside of field names multilingual (any other text in the form), wrap it in an [icl] tag.

For example, supposing we’re translating the label for the country name selector:

Select Your Country

Wrap the text that needs to be translated with [icl] and [/icl] tags:

[icl]Select Your Country[/icl]

Like in the previous example, let’s also add the string context to the translation tag.

[icl select-country-label]Select Your Country[/icl]

The result of what we just did appears below. This is a contact form (or at least part of it), which will appear fully multilingual to visitors.

Multilingual contact form

Multilingual contact form

Making user feedback multilingual

We’ll use a similar technique to translate the feedback that visitors see after submitting contact forms. This means, we’ll wrap the feedback text in [icl] tags as well.

Let’s make the confirmation email multilingual.

Your message was sent successfully. Thanks.

Wrap it by [icl] tags. Also, include the string context in the tag (so that we know what we’re translating later).

[icl success-response]Your message was sent successfully. Thanks.[/icl]

Making the message multilingual

Making the message multilingual

Once we’ve done this procedure and wrapped everything that needs to be translated in [icl] tags, save the form. The form is ready to be displayed in multiple languages. To translate the strings, go to ‘WPML’->’String translation’. The texts you created in the contact form will appear them and you can provide translation to all the site’s languages. The contact form will display correctly in different languages and visitors will get feedback in their language.

Need help?

CF7 author provides extensive support, including free documentation, paid troubleshooting and customization service. Check out the different CF7 support options and see which one is best for you.

30 Responses to “How to use Contact Form 7 in multilingual websites”

  1. Al says:

    It took me a while to figure out that I should be making the changes related to icl codes inside the admin settings panel for the contact form 7 plugin.

    I can’t figure out from your instructions how to change the user feedback.

    I can’t edit the messages in the pluggin settings.

    Is there a messages file that needs to be modified?

  2. Al says:

    My Bad.

    The text is editable.

    For me, the user interface was such that I could not tell that I could edit the text.

  3. zxl says:

    Hi,
    How do I get the quiz to show up for string translation? My quiz tag is:

    [quiz quiz-530 "This year is the 60th anniversary of the founding of the People's Republic of China. In what year was the People's Republic of China founded?|1949"]

    I tried inserting ‘icl’ right after the [quiz quiz-530 part, but it still didn’t show up under string translation. In fact, I don’t see the quiz at all in the foreign language page.
    Thanks.

  4. Piet says:

    I haven’t tried this yet, but I am sure it will work brilliantly!

    My main reason for not trying this as of yet is that I am using a re-direct to a confirmation page. As this is obviously a different page per language, what would be the best way to go about this?

    Thanks to both the WPML team and takayukister for collaborating on this to making it work so well!

    Piet

  5. [...] après il vous faut un formulaire de contact. J’ai bien aimé Contact Form 7 qui plus est, est compatible avec WPML cité plus haut (cf ce tuto chez WPML) [...]

  6. enad says:

    hi i cant seem to figure out how to publish a form. i tried copying the tags but they just showed up as tags

  7. Peterek says:

    Hello WPML crew, thanks for your work!

    The plugin (v1.7.1) is perfect but I just can’t get it to (fully) work with contact-form-7 (v2.1.2). I am using wordpress 2.9.2

    It’s more related to CF7, but I will try here first :)

    The problem is related to wpcf7_get_request_uri() function which – for some reason – does not return url with language code. Consider a form placed here:

    http://mysite.com/en/contact-us

    Then the wpcf7_get_request_uri() function returns only “/contact-us” (so the form is submitted to “http://mysite.com/contact-us”). After submmiting form data to mysite.com/contact-us the emails are sent BUT user sees 404 error message (The “Your message was sent successfully. Thanks.” message is NOT displayed).

    I tried to hack CF7 code (include/classes.php, form_htm function) with the use of ICL_LANGUAGE_CODE constant, but simply it’s not defined until this code executes.

    Does anyone solved this kind of problem? Is it something with my site setup (.htaccess?), bug or configuration problem?

    • Timo says:

      I have a similar problem:
      After successfully using Contact Form 7 on the english version, when publishing the Spanish content (different path: http://www.ecovenao.com/es/), we are simply creating a Spanish copy of each English form and put them on the correspondent spanish pages.
      The submission of the forms works great, however the validation and the feedback messages are not working on any of the /es/ – pages.
      Any solution for this problem yet?
      SIncerely,
      Timo

  8. Hyden says:

    contact form 7 seems dosen’t support this any more. I got a message when using this way:
    This contact form contains [icl] tags, but they are obsolete and no longer functioning on this version of Contact Form 7. There is a simpler way for creating contact forms of other languages and you are recommended to use it.

  9. Eric B. says:

    @Peterek

    Solved!

    Place a condition into the classes.php directly on the wpcf7_get_request_uri() , line 41.

    e.g.

    if(ICL_LANGUAGE_CODE==’en’){
    $url = ‘/en’. wpcf7_get_request_uri();
    }
    if(ICL_LANGUAGE_CODE==’fr’){
    $url = wpcf7_get_request_uri();
    }

  10. Kitich says:

    new CF7 (I have tried 2.1.2 and 2.2.1) doesn’t support [icl]-tag. It want you to create several forms for different languages. It took me 2 hours to understand the problem and I had to install CF7 2.0 to provide multilingual form :(

    All is OK, but [contact-form]-tag is replaced by CF7-plugin before it is translated by WPML. Please, repair this and we will have 2 perfect plugins for WP

  11. Alain says:

    For all people running in to the problem that all the above doesn’t work anymore for newer versions of CF7.

    If you simply overwrite the icl.php file in the modules folder by an icl.php from an older version (I used 2.0.7) it will work again..

  12. bamg says:

    hmm! it seem that I don’t understand where to make those changes…
    I put them in the contact form… you can see them in the page in your browser… (of course!)

    where shall I go to add these tages?

    thanks

  13. Janis says:

    Amir, this article is realy a time wasting article!!! [icl] is not suported anymore!

  14. Harvey says:

    * groan * why is this no longer supported, and why have I just wasted my time reading and trying to get this all to work? Do we now have to pay for Gravity Forms for proper WPML integration with forms?

  15. Yumi says:

    hi!
    I wrote ‘icl_register_string(‘SidebarLogin’, ‘welcome1′, ‘Welcome”.’);’ in functions.php.
    and I wrote ‘[icl welcome1]Welcome[icl]‘ in the textfield of plugin admin page.
    then it appeared on the browser like ‘[icl welcome1]Welcome[icl]‘. shortcode wasn’t translate to variable. what should I do?
    Thanks.

    • Amir says:

      I think that CF7 author might have removed that WPML support from his plugin some time ago. I’ll update this in the page.

  16. @cristian says:

    I also use contactform7 but in a different way. I make a form for each language and then inserted into the corresponding translation.

  17. Z says:

    1. download contact-form-7 2.0
    2. copy contact-form-7\modules\icl.php to the lastst version contact-form-7 \modules\
    3. edit icl.php, find this line
    $content = __(trim( $content ),’venths’); or $content = __(trim( $content );

    function icl_wpcf7_shortcode_handler( $tag ) {

    if ( ! is_array( $tag ) )
    return ”;

    $name = $tag['name'];
    $values = (array) $tag['values'];
    $content = $tag['content'];

    // Just return the content.

    $content = __(trim( $content ),’venths’);
    if ( ! empty( $content ) )
    return $content;

    $value = trim( $values[0] );
    if ( ! empty( $value ) )
    return $value;

    return ”;
    }

    4. remove waring line,if u want. enjoy

Leave a Reply

Please leave here comments about this page only.
For technical support and feature suggestions, head to our forum. We are waiting there!

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>