use yii\widgets\ActiveForm; use yii\helpers\Html; $form = ActiveForm::begin(); echo $form->field($model, 'username')->textInput(); echo $form->field($model, 'email')->textInput(); echo Html::submitButton('Submit', ['class' => 'btn btn-primary']); ActiveForm::end();
use yii\widgets\ActiveForm; use yii\helpers\Html; $form = ActiveForm::begin(); echo $form->field($model, 'username')->textInput(); echo $form->field($model, 'email')->textInput(); echo $form->field($model, 'password')->passwordInput(); echo Html::submitButton('Submit', ['class' => 'btn btn-primary']); ActiveForm::end();Here, a third input field - password - was added to the form. Note how its input field type is defined as "password" rather than "text". This example highlights the built-in validation feature of ActiveForm. If any errors are detected in the validation process, the widget will generate a message to the user. In conclusion, ActiveForm is a versatile Yii widget that enables easy creation of interactive web forms. With various features such as client-side validation and error handling, the ActiveForm widget is an essential tool for any Yii developer when creating interactive web applications.