Answer the question
In order to leave comments, you need to log in
How to accept integer data in yii2?
Gentlemen, there is a form. The form submits lines, of course.
In one of the forms for deleting a user, a hidden input with id is submitted.
id must be an integer.
If I write in rules like this:
public function rules() {
return [
['userid', 'required'],
['userid', 'integer', 'max' => 32, 'message' => 'Value should to be an integer'],
];
}
Answer the question
In order to leave comments, you need to log in
Actually, when checking, a string is parsed, so if you specify that the value should be an integer, then a pattern is checked: integerPattern .
So exactly what you want will come. Everything should be fine.
[['userid'], 'integer', 'max' => 32, 'message' => 'Value should to be an integer']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question