Yii2 - ActiveForm example

ActiveForm with model

<?php $form = ActiveForm::begin() ?>
<?= $form->field($model, 'username')->textInput() ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
<?php ActiveForm::end() ?>

ActiveForm with model and custom url

<?php $form = ActiveForm::begin(['action' => ['site/login']]) ?>
<?= $form->field($model, 'username')->textInput() ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
<?php ActiveForm::end() ?>

ActiveForm without model

<?= Html::beginForm() ?>
<label>Username</label>
<?= Html::input('text', 'LoginForm[username]', null, ['class' => 'form-group form-control']) ?>
<label>Password</label>
<?= Html::input('text', 'LoginForm[password]', null, ['class' => 'form-group form-control']) ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary form-group']) ?>
<?= Html::endForm() ?>

ActiveForm without model and custom url

<?= Html::beginForm(['site/login'], 'post') ?>
<label>Username</label>
<?= Html::input('text', 'LoginForm[username]', null, ['class' => 'form-group form-control']) ?>
<label>Password</label>
<?= Html::input('text', 'LoginForm[password]', null, ['class' => 'form-group form-control']) ?>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary form-group']) ?>
<?= Html::endForm() ?>