Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing textbox in the Yii2 form

Tags:

php

yii2

I am following a tutorial and it is using bootstrap. I am not sure how I would resize textbox for Lan_Id, Name and Employee_Number in it. I think, I am starting to understand Yii framework.

Here is the view userForm.php:

<?php

    use yii\helpers\HTML;
    use yii\widgets\ActiveForm;

    ?>
    <?php
        if(Yii::$app->session->hasFlash('success'))
        {
            echo Yii::$app->session->getFlash('success');
        }
    ?>
    <?php $form = ActiveForm::begin();?>
    <?= $form->field($model,'Lan_Id');?>
    <?= $form->field($model,'Name');?>
    <?= $form->field($model,'Employee_Number');?>
    <?= Html::submitButton('Submit', ['class'=>'btn btn-success']);

Here is the model UserForm.php:

<?php

namespace app\models;

use yii\base\Model;

class UserForm extends Model
{

    public $Lan_Id;
    public $Name;
    public $Employee_Number;

    public function rules()
    {
        return [
            [['Lan_Id','Name','Employee_Number'],'required'],
        ];
    }
}
like image 319
Veronica Avatar asked Dec 16 '14 20:12

Veronica


1 Answers

If you want to change the input text field length:

 <?= $form->field($model,'Lan_Id')->textInput(['maxlength'=>10]);?>

Above code limits the maximum length of characters to 10.

But if you want to change the input text field size:

 <?= $form->field($model,'Lan_Id')->textInput(['style'=>'width:100px']);?>

Above code changes the input text field width to 100px. You can also have both:

 <?= $form->field($model,'Lan_Id')->textInput(['maxlength'=>10,'style'=>'width:100px']);?>

It is highly recommended to take a look at Yii2's official document: http://www.yiiframework.com/doc-2.0/yii-widgets-activefield.html

like image 66
Ali MasudianPour Avatar answered Sep 25 '22 22:09

Ali MasudianPour