Title.... Because just started to learn YII2 framework, know the model of the Rules method can fill in the validation rules, but he seems to only verify the PC-side page with ActiveForm generated form data, then the mobile client submitted by the form data can also use the rules method of validation rule?
Reply content:
Title.... Because just started to learn YII2 framework, know the model of the Rules method can fill in the validation rules, but he seems to only verify the PC-side page with ActiveForm generated form data, then the mobile client submitted by the form data can also use the rules method of validation rule?
He seems to be validating only the form data generated by the PC-side page with ActiveForm.
The verdict is wrong.
I guess you may have a problem, the key is to assign a value in the block?
In Yii2, ActiveForm
you will default to the current generated form definition one 名称
, yes, as you can see:
Then LoginForm
you can do this when you receive the data:
$form = new LoginForm;$form->load(Yii::$app->requeset->post());
And the data on the phone to the server side is long like this?
[ 'username' => 'beep', ...]
So we can do this when we use the form to receive:
$form->load(Yii::$app->request->post(), '');//亦或$form->setAttributes(Yii::$app->request->post());
Then, verify that:
$form->validate();var_dump($form->errors);
To familiarize yourself with the documentation?