Author Topic: Again Cyrillic entries error  (Read 376 times)

Offline rumen

  • Posts: 365
Again Cyrillic entries error
« on: November 13, 2018, 11:33:29 AM »
I got again Cyrillic entries in Bakery 1.83 in the order form error but this time the problem is not in the DB table collation and not in the template ... so what I miss?

Rumen

Offline jacobi22

  • Posts: 5199
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Again Cyrillic entries error
« Reply #1 on: November 13, 2018, 12:02:44 PM »
Bakery is prepared for Latin characters only

here the form-check from save_form.php for the company field

Code: [Select]
if (!preg_match('#^[\p{Latin}'.$us.'0-9.+&\s\-]{0,50}$#u', $value)) {
you can try it with this

Code: [Select]
if (!preg_match('#^[\p{Cyrillic}+|\p{Latin}'.$us.'0-9.+&\s\-]{0,50}$#u', $value)) {but not sure, not possible, to test it for me at the moment

P.S.: there are a lot of field checks for nearly every field, be very carefull with this and try to understand first,  how the preg_match works in every check
for example:
country - allowed only two letters A-Z
Code: [Select]
if (!preg_match('#^[A-Z]{2}$#u', $value)) {
maybe it works with
Code: [Select]
if (!preg_match (#^[a-zA-Z\p{Cyrillic}\d\s\-]+$/u', $value)) {
or with this for Latin Users also
Code: [Select]
if (!preg_match('#^[\p{Cyrillic}+|\p{Latin}'.$us.'0-9.+&\s\-]{2}$#u', $value)) {
go step by step and check the form after every chenges in the field check
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #2 on: November 13, 2018, 12:46:09 PM »
I have changed the fields, but got same error. I remember I got the same error before, but it was in ver. 1.77. Now this is ver. 1.83, otherwise I would copy the files from the other one that works :(

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #3 on: November 13, 2018, 12:53:04 PM »
In this file save_form.php I see there is Cyrillic support.

Offline jacobi22

  • Posts: 5199
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Again Cyrillic entries error
« Reply #4 on: November 13, 2018, 01:54:12 PM »
plaese change this code for a test to

Code: [Select]
if (!empty($MOD_BAKERY['ADD_CHARSET'])) {
    switch (strtolower($MOD_BAKERY['ADD_CHARSET'])) {
        case 'cyrillic':
//            $us = '\p{Cyrillic}';
            $us = '+|\p{Cyrillic}';
            break;
        case 'greek':
//            $us = '\p{Greek}';
            $us = '+|\p{Greek}';
            break;
        case 'hebrew':
//            $us = '\p{Hebrew}';
            $us = '+|\p{Hebrew}';
            break;
        case 'arabic':
//            $us = '\p{Arabic}';
            $us = '+|\p{Arabic}';
            break;
    }
}

works for me with a regex-tester
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #5 on: November 13, 2018, 02:40:14 PM »
I have change it, but I got the same error   what can be the reason?

Offline jacobi22

  • Posts: 5199
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Again Cyrillic entries error
« Reply #6 on: November 13, 2018, 04:05:42 PM »
There is a logical problem inside of the proof methods, i need some minutes to repair this, but i have to check every method first
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline jacobi22

  • Posts: 5199
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Again Cyrillic entries error
« Reply #7 on: November 13, 2018, 04:30:57 PM »
so, next try  (works for me with latin, cyrillic, hebrew, arabic) -
the charset like this come's from the translation file - in this case specially from the RU.php. All Pages from the Latin languages has the default charset "latin" and no specially definition in the language files.
it's very important, that the translator of the language file set this charset in the language file, otherwhise, he get latin as charset, so check also your bulgarian language file for that
it's also important, that the visited page has this selected language (see page settings). For example: a page with language = english can in this form only work with latin characters, but not with cyrillic
but the check for latin chars work in every language, that means: you can use also latin chars on a russian or arabic page

i hope, it works for you also

Quote


$us 
'';
if (!empty(
$MOD_BAKERY['ADD_CHARSET'])) {
    switch (
strtolower($MOD_BAKERY['ADD_CHARSET'])) {
        case 
'cyrillic':
            
$us '\p{Cyrillic}';
            break;
        case 
'greek':
            
$us '\p{Greek}';
            break;
        case 
'hebrew':
            
$us '\p{Hebrew}';
            break;
        case 
'arabic':
            
$us '\p{Arabic}';
            break;
        default:
            
$us '\p{Latin}';
            break;
    }
}

// Check the textfields
foreach ($_POST as $field => $value) {
    if (
$field != 'pay_methods') {
        
$field strip_tags($field);
        
$value strip_tags($value);

        if (
strpos($field'company') !== false) {
            if (!
preg_match('/^[a-zA-Z'$us .'0-9.+&\s\-]{1,50}+$/u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_NAME'];
            }
        }

        if (
strpos($field'first_name') !== false) {
            if (!
preg_match('/^[a-zA-Z'$us .'0-9\s\-]{1,50}+$/u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . '  ' $MOD_BAKERY['ERR_INVAL_NAME'];
            }
        }

        if (
strpos($field'last_name') !== false) {
            if (!
preg_match('/^[a-zA-Z'$us .'0-9\s\-]{1,50}+$/u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_NAME'];
            }else{echo 
"geht doch";}
        }

        if (
strpos($field'cust_tax_no') !== false &&
                
strpos($setting_tax_group$setting_shop_country) !== false) {
            include(
'check_vat.php');
            
$value trim($value);
            if (!
check_vat($value$setting_tax_group)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_CUST_TAX_NO'];
            }
        }

        if (
strpos($field'street') !== false) {
            if (!
preg_match('/^[a-zA-Z'$us .'0-9.+&\s\-]{1,50}$/u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_STREET'];
            }
        }

        if (
strpos($field'city') !== false) {
            if (!
preg_match('/^[a-zA-Z'$us .'0-9.+&\s\-]{1,50}$/u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_CITY'];
            }
        }

        if (
strpos($field'state') !== false) {
            if (!
preg_match('/^[a-zA-Z'$us .'0-9.+&\s\-]{1,50}$/u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_STATE'];
            }
        }

        if (
strpos($field'country') !== false) {
            if (!
preg_match('#^[A-Z]{2}$#u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_COUNTRY'];
            }
        }

        if (
strpos($field'email') !== false) {
            if (!
preg_match('#^.+@.+\..+$#u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_EMAIL'];
            }
        }

        if (
strpos($field'zip') !== false) {
            if (!
preg_match('#^[A-Za-z0-9\s\-]{4,10}$#u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_ZIP'];
            }
        }

        if (
strpos($field'phone') !== false) {
            if (!
preg_match('#^[0-9)(xX+./\s\-]{7,20}$#u'$value)) {
                
$error_bg[] = $field;
                
$errors[] = htmlspecialchars($valueENT_QUOTES) . ' ' $MOD_BAKERY['ERR_INVAL_PHONE'];
            }
        }

        $
$field strip_tags(trim($value));
    }
}
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #8 on: November 13, 2018, 11:26:11 PM »
I have changed the code, but same error appeared.

Offline jacobi22

  • Posts: 5199
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Again Cyrillic entries error
« Reply #9 on: November 13, 2018, 11:43:51 PM »
what can i say... it works for me with some fictive google translations in the fields -> https://gyazo.com/2ee4eb5d54f18afdd4abfc9e2265771d

is it russian or bulgarian?
you have this line in the bakery-language file?
Code: [Select]
$MOD_BAKERY['ADD_CHARSET'] = 'Cyrillic';
one line from the code has too much content, in the area for the last name at the end, remove this

else{echo "geht doch";}

but it has nothing to do with the form check

Have you try your version from the 1.73?
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #10 on: November 14, 2018, 01:05:36 AM »
I took the language file from another site with Bakery which works. But there is no such raw there. I put the raw there and now it works (just should not have , and . in the fields) but works and again the same problem with the mail confirmation like before .... both e-mails not readable:

Code: [Select]
Здравейте Румен Запрянов

Благодарим Ви за поръчката от El Tempo.
Ето детайли за вашата поръчка:

Номер: 0002
Име: Пилешка супа
Хляб: Без хляб
Количество: 1
Цена: BGN 2.90
Доставка: BGN 1.00
Сума: BGN 2.90

-------------------------------------
Междинен сбор: BGN 2.90
Цена за доставката: BGN 1.00
Inclusive 0.0% Данък: BGN 0.00
-------------------------------------
-------------------------------------
Общо: BGN 3.90
-------------------------------------

Поръчката ще бъде доставена на адрес:

Румен Запрянов
Бусманци ул Циклама 2
1520 София
София


+359876415004


Вие избрахте да платите при доставката на куриера.


Благодарим Ви за доверието в нас.

Поздрави,
El Tempo

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #11 on: November 14, 2018, 01:07:36 AM »
Like here  https://forum.WebsiteBaker.org/index.php/topic,30597.msg213299.html#msg213299  ,    but now all DataBase tables are UTF8 for sure.

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #12 on: November 14, 2018, 01:11:33 AM »
Is there a difference for WB if some of the tables are UTF8_unicode_ci other tables are UTF8_general_ci? Because they have difference!

Offline jacobi22

  • Posts: 5199
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Again Cyrillic entries error
« Reply #13 on: November 14, 2018, 01:39:30 AM »
Quote
just should not have , and . in the fields

you need comma and the point? - If YES, which kind of field

Quote
again the same problem with the mail confirmation like before .... both e-mails not readable:

jau, thats not utf8, thats htmlspecialchars
was the problem solved in last time?

can you make a export from the database table mod_bakery_customer - i need only one complete order from there in sql-format.
i'll look to the way from the invoice from the buy-button into the database and from there to the email and the bakery administration

for a first try, go to view_confirmation.p hp  ~ line 160ff

Original-Code
Code: [Select]
// Make email headers
            if (defined('DEFAULT_CHARSET')) {
                $charset = DEFAULT_CHARSET;
            } else {
                $charset = 'utf-8';
            }

change it to

Code: [Select]
$charset = 'utf-8';
it's not longer needed to use if/else here, because there is only one charset possible, and this is utf8

i did not found any code to change the content from the invoice on the way into the email, so i think, you have the htmlspecialchars also in the database, but i have to build a russian bakery page with russion items and descriptions, to check this


Quote
Is there a difference for WB if some of the tables are UTF8_unicode_ci other tables are UTF8_general_ci?

yes, a small different, but it doesn't matter, what you use. both works
_unicode_ci is the default setting for WB and _general_ci is the default setting in your database. if some module not submit this character set, the database use the selected charset & collation

Some description from Stackoverflow
Quote
For any Unicode character set, operations performed using the _general_ci collation are faster than those for the _unicode_ci collation. For example, comparisons for the utf8_general_ci collation are faster, but slightly less correct, than comparisons for utf8_unicode_ci. The reason for this is that utf8_unicode_ci supports mappings such as expansions; that is, when one character compares as equal to combinations of other characters. For example, in German and some other languages “ß” is equal to “ss”. utf8_unicode_ci also supports contractions and ignorable characters. utf8_general_ci is a legacy collation that does not support expansions, contractions, or ignorable characters. It can make only one-to-one comparisons between characters.

you can also use utf8mb4_unicode_ci

change the line in your config.php like this

Code: [Select]
define('DB_CHARSET',      'utf8mb4_unicode_ci');
and start the upgrade-script. there is no risk, if you have all table with one of the utf8-characters like utf8mb4_unicode_ci, utf8mb4_general_ci, utf8_unicode_ci or utf8_general_ci

if you use emoticons in ckeditor, utf8mb4_......_ci is neccesary
« Last Edit: November 14, 2018, 01:45:09 AM by jacobi22 »
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #14 on: November 14, 2018, 08:49:14 AM »
I have changed the code with:

Code: [Select]
$charset = 'utf-8';
But no effect at all, same error.

I sent you by mail the data.

Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #15 on: November 15, 2018, 10:00:14 PM »
So the issue was solved!!!

I just took the EN.php language file, we input the line for Cyrillic there and I made new translation of the file. Now works fine!


Offline rumen

  • Posts: 365
Re: Again Cyrillic entries error
« Reply #16 on: November 15, 2018, 10:01:21 PM »
Special thanks to jacobi22 for the help. THanks again brother!


Offline jacobi22

  • Posts: 5199
  • Gender: Male
  • Support also via PM or EMail
    • Jacobi22
Re: Again Cyrillic entries error
« Reply #17 on: November 15, 2018, 11:39:36 PM »
additional informations for everybody:

it's very important, that the language files are converted to utf8 without boom
Use Notepad++ or other semi-proffessional editors, to edit in this files or to convert it
Probleme sind da, um sie zu lösen, nicht, um nach Ausreden zu suchen.