I am trying to validate a simple form in Yii2 framework. validation method on model is -
/**
* {@inheritdoc}
*/
public function rules()
{
return array(
array('name', 'required'),
// ... other rules
);
}
When i try to make request it says -
array(1) { ["name"]=> array(1) { [0]=> string(21) "Name cannot be blank." } }
But the thing is i am sending name field in request ( POST ). But after providing name field , it gives an error.
If i do var_dump for request It shows me that name field is in there the request.
Here is the var_dump of request data and the validation error. -
array(1) { ["name"]=> string(6) "distro" } array(1) { ["name"]=> array(1) { [0]=> string(21) "Name cannot be blank." } }
Thank you in advance.
$model->name = Yii::$app->request->post("username");before validate - Paritosh Mahale$model->load(Yii::$app->request->post())method. This method will help you to map the requested data to the model. - Shifrin