Modx update formit table greek characters issue

Hello, i have formit forms and i gave access to users so they can edit them.
Whenever a user clicks save to update his form i am making 2 mysql queries

The first is in the formit table:

$sql = $modx->query("
                     UPDATE `modx_formit_forms`
                     SET `values` = '$valuesjson'
                     WHERE id='$formid'
              ");

The second is in a custom table

$sql2 = $modx->query("
                     UPDATE `modx_users_forms`
                     SET `body` = '$valuesobject->body',
                         `initial_images` = '$IMAGES_TO_SAVE' 
                     WHERE formid='$formid'
              ");

In both tables im adding greek characters but only in the custom table the greek chars are stored correctly in the formit table the greek chars are saved like below (see name and body field):

{
“name”:“This is a test ignore u03b4u03bau03c6u03c3u03bau03c6u03c3u03bau03c6u03bbu03c3 u03b4u03bau03c6u03bcu03bbu03bau03c3u03c6u03bcu03c6”,
“body”:“dfsfsfsf u03c6u03bbu03c3u03c6u03beu03c3u03bau03c6u03c3u03bau03beu03c6u03bdu03c3u03bau03beu03c6u03bdu03c3u03c6”,
“imagesQueue”:“0”,
“imagesLinks”:"",
“imagesLinksTOREMOVE”:"",
“file”:"",
“tk”:"",
“odos”:"",
“other_area_info”:"",
“datewhat”:“03/09/2019”,
“other_testimony_info”:"",
“image”:""
}

The only differnce in the 2 tables is that formit VALUES fields stores multiple fields in json format and in the custom table am just updating a single field.

So i know that the problem is related to how formit handles this field

Any help?

Please be aware that your code may be vulnerable to SQL injections when you use $modx->query instead of the xPDO query builder and objects. If $formid or $valuesjson/$valuesobject/$IMAGES_TO_SAVE can contain arbitrary user-provided input that can pose a significant security risk.

What you’re seeing is standard json_encode behavior in PHP:

You can use the JSON_UNESCAPED_UNICODE flag to make it store regular UTF-8 characters. Make sure the tables are all set to utf8 collations if you do.

2 Likes