WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Contact Form 7] Accented characters in checkbox

[Resolved] [Plugin: Contact Form 7] Accented characters in checkbox

  • It seems Contact Form 7 is having trouble with accents in checkbox fields.

    When using accented characters in values (e.g. [checkbox my-choices use_label_element “région1” “région2”]) the field doesn’t display at all in the form.
    If replaced with html entities (i.e. [checkbox my-choices use_label_element “r_eacute;gion1” “r_eacute;gion2”]) the field is displayed, but the value won’t show in the email. <note: I replaced the & with a _ in here, it seems there’s no way to have it show properly otherwise>

    With mixed values (i.e. some values with html entities and other with only ascii characters), the ticked option shows up in the email if it is ascii only, not if it contains an html entity.

    Is there a way to have accented characters work with a checkbox input at all ? Or maybe a way to differentiate the value and its label ?

    http://wordpress.org/extend/plugins/contact-form-7/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Takayuki Miyoshi

    @takayukister

    When using accented characters in values (e.g. [checkbox my-choices use_label_element “région1” “région2”]) the field doesn’t display at all in the form.

    This works on my side.

    Well, it works with “région” but not with “ràgion”

    Plugin Author Takayuki Miyoshi

    @takayukister

    Tested with “ràgion”. It still works.

    I’m glad it works for you, but unfortunately here it doesn’t 🙁
    with [checkbox my-choices use_label_element “ràgion1” “région2”] I only get the br tag and no other markup.
    I’m using Version 3.0.1 of the plugin and Version 3.2.1 of wordpress.

    I eventually found out the source of the problem…

    In contact-form-7/includes/shortcodes.php, line 39 (within function normalize_space_cb), there is a preg_replace that doesn’t handle unicode.

    Replacing
    $attr = trim( preg_replace( ‘/\s+/’, ‘ ‘, $m[3] ) );
    with
    $attr = trim( preg_replace( ‘/\s+/u’, ‘ ‘, $m[3] ) );
    solves the problem !

    I hope you can fix this in the source for everyone to benefit from it 🙂

    Plugin Author Takayuki Miyoshi

    @takayukister

    OK, thanks. But I can’t understand why adding the ‘u’ flag solves the problem.

    The manual says:

    u (PCRE8)
    This modifier turns on additional functionality of PCRE that is incompatible with Perl. Pattern strings are treated as UTF-8. This modifier is available from PHP 4.1.0 or greater on Unix and from PHP 4.2.3 on win32. UTF-8 validity of the pattern is checked since PHP 4.3.5.

    But the pattern string is only \s+. How does it affect in that case? Do you have any further references about it?

    I think the “u” modifier doesn’t only treat the pattern as UTF-8, but considers the target string as UTF-8 encoded too. That’s how I’ve always been using it, and I’m a bit surprised by rereading the doc to find out it’s not really what it says.

    Anyway, without it, some characters like “à” are replaced with the ? in a diamond, while with it the string is only altered on whitespaces, and other characters are not altered, which is what we’re aiming for here.

    I think the problem was due to a bug in php 5.3.4 on windows. Since my last post I noticed some toher places where the “à” character was not handled right. Upgrading to 5.3.8 fixed it.
    Just though you might wanna know about that.

    Plugin Author Takayuki Miyoshi

    @takayukister

    somatt, thank you!

    Thanks, somatt!
    I don’t have the possibility to upgrade the PHP, but your code worked to fix the same problem with a textarea containing accented characters.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Resolved] [Plugin: Contact Form 7] Accented characters in checkbox’ is closed to new replies.