E
E
Evgeny Bukharev2015-04-02 17:29:52
Yii
Evgeny Bukharev, 2015-04-02 17:29:52

Different validation values ​​on client and server in Yii?

Hello comrades!!
Faced such a problem, namely with different validation values ​​on the client and on the server in YII.
The essence of the problem is as follows:
1. There is a validation rule
array('desc', 'length', 'encoding' => 'utf-8', 'max' => 150, 'tooLong' => 'Comment must not exceed 150 characters' ) 2. In the
textarea for this attribute, I enter two characters per line:
!d
!d
!d
, etc.
passes, but does not pass on the server
4. I know that the problem is in the line break character, namely 150 characters with line breaks on the client are equal to 200 characters on the server, that is, the line break character on the client is 1 character, on the server 2
5. unix / windows there is no difference on which os server , the problem is both there and there
5. How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Bukharev, 2015-04-03
@evgenybuckharev

Evgeny Dozhdikov :

if(function_exists('mb_strlen') && $this->encoding!==false)
      $length=mb_strlen($value, $this->encoding ? $this->encoding : Yii::app()->charset);
    else
      $length=strlen($value);

Here is the code that is directly responsible for checking the number of characters on the server, function_exists('mb_strlen') gives TRUE for me, although there is a rather strange condition in if, if $this->encoding!==false, then check $this->encoding ? $this->encoding : Yii::app()->charset makes no sense, but nevertheless $this->encoding is specified in my rule, so it works $length=mb_strlen($value, $this->encoding ? $ this->encoding : Yii::app()->charset); which gives the wrong number of characters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question