Yii2 ActiveForm Inputs and Custom Inputs

  1. Number Input
<?= $form->field($model, 'price')->textInput([
    'maxlength' => true,
    'type' => 'number'
]);?>

2. Custom File Input

Ref. Link https://getbootstrap.com/docs/4.6/components/input-group/#custom-file-input

<?= $form->field($model, 'imageFile', [
        'template' => '
                <div class="custom-file">
                    {input}
                    {label}
                    {error}
                </div>
            ',
        'labelOptions' => ['class' => 'custom-file-label'],
        'inputOptions' => ['class' => 'custom-file-input']
    ])->textInput(['type' => 'file']) ?>

‘template’ must match the format of the HTML code. e.g. first {input} which will render the input field, then {label} that renders a label and lastly the {error} which will render the errors div below the input field. Yii will display the input error by swapping the {error} block.

Bootstrap4 widgets/ActiveField.php defines the template format as {label} \n {input} \n {hint} \n {error}.

Running low on budget? Get the best Shared hosting at an Affordable Rate!