Reputation: 1121
This is my drop-down list:
<?= $form->field($model, 'course')->dropDownList($dataPost, ['prompt' => 'Select a Course']); ?>
How can I put a validation rule in model so it gives error when a 'course' is not selected on form submission?
Upvotes: 0
Views: 3834
Reputation: 4319
Just make sure that the attribute course
is required in the model using the rules method:
public function rules()
{
return [
[['course'], 'required'],
];
}
Upvotes: 1