WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
[resolved] Accented characters in checkbox (11 posts)

  1. somatt
    Member
    Posted 2 years ago #

    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/

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 2 years ago #

    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.

  3. somatt
    Member
    Posted 2 years ago #

    Well, it works with "région" but not with "ràgion"

  4. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 2 years ago #

    Tested with "ràgion". It still works.

  5. somatt
    Member
    Posted 2 years ago #

    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.

  6. somatt
    Member
    Posted 2 years ago #

    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 :)

  7. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 2 years ago #

    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?

  8. somatt
    Member
    Posted 2 years ago #

    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.

  9. somatt
    Member
    Posted 2 years ago #

    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.

  10. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 2 years ago #

    somatt, thank you!

  11. kisssy
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic