Yii Framework 2.0 ActiveForm Input Fields
'yii\widgets\ActiveForm' class is used to create a form and 'yii\helpers\Html' class is used to display the different type of HTML input fields like buttons, textbox, select box etc.ActiveForm::begin() - creates a form instance and beginning of the form. ActiveForm::begin() and ActiveForm::end() - All of the content placed between this.
Use the namespace For ActiveForm
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
'ActiveForm' namespace is very important to create the a active form and 'Html' namespace is very useful to display the different html input fields.
Active Form Begin And End
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
//$form = ActiveForm::begin(); //Default Active Form begin
$form = ActiveForm::begin([
'id' => 'active-form',
'options' => [
'class' => 'form-horizontal',
'enctype' => 'multipart/form-data'
],
])
/* ADD FORM FIELDS */
ActiveForm::end();
?>
Yii2 Text Input Field
//Format 1
<?= $form->field($model,'name'); ?>
//Format 2
<?= $form->field($model, 'name')->textInput()->hint('Please enter your name')->label('Name') ?>
yii2 ActiveForm numeric textfield
yii2 textinput to accept only numeric input.
You can use
->textInput(['type' => 'number']
HTML example
<input type="number" min="0" max="10"></input>
<?= $form->field($modelSalesitem, "qty")->textInput(['type' => 'number', 'maxlength' => true, 'onChange' => 'checkStock(this.id);',])->label(false)->error(FALSE) ?>
No comments:
Post a Comment