'Yii2 form does not work — Class 'yii\bootstrap\ActiveForm' not found
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
$form = ActiveForm::begin(['id' => 'login-form']);
ActiveForm::end();
?>
If i run this code the following error will occur.
Fatal error: Class 'yii\bootstrap\ActiveForm' not found in E:\wamp\www\yii2-paypal-master\backend\views\site\login.php on line 6
Kindly help me to fix this.
Thanks
Solution 1:[1]
Replace
use yii\bootstrap\ActiveForm;
with
use yii\widgets\ActiveForm;
Form:
<?php $form = ActiveForm::begin([
'options'=>['enctype'=>'multipart/form-data'],
]);
?>
<?= $form->errorSummary($model) ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
Solution 2:[2]
First, check the file assets/AppAsset.php if your Class App Asset is like mine, using Boostrap 3 or 4 or o:
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap4\BootstrapAsset',
];
}
You need to change it to use yii\bootstrap\ActiveForm; change this to instead use yii\bootstrap4\ActiveForm; it worked for me.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Muhammad Shahzad |
| Solution 2 | Jeremy Caney |
