PHP code example of fgh151 / yii2-form-fields

1. Go to this page and download the library: Download fgh151/yii2-form-fields library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fgh151 / yii2-form-fields example snippets


$form = ActiveForm::begin();
echo \fgh151\fields\InputWidget::widget([
    'model' => $model,
    'attribute' => 'attributeName',
    'type' => \fgh151\fields\FieldTypes::getByName('text'), //default text
]);
ActiveForm::end();

echo \fgh151\fields\InputWidget::widget([
    'model' => new \yii\base\DynamicModel(['attributeName']),
    'attribute' => 'attributeName',
]);

echo \fgh151\fields\InputWidget::widget([
    'model' => new \yii\base\DynamicModel(['attributeName']),
    'attribute' => 'attributeName',
    'options' => [
                'label' => 'Custom label',
                'value' => 'Some value',
    ]
]);

echo \fgh151\fields\InputWidget::widget([
    'model' => new \yii\base\DynamicModel(['FirstName']),
    'attribute' => 'FirstName',
    'type' => 6, //You can specify direct see \fgh151\fields\FieldTypes
    'options' => [
        'variants' => [
            ['label' => 'var1', 'value' => 'var1'],
            ['label' => 'var2', 'value' => 'var2'],
            ['label' => 'var3', 'value' => 'var3'],
        ]
    ]
]);

echo \fgh151\fields\InputWidget::widget([
    'model' => new \yii\base\DynamicModel(['FirstName']),
    'attribute' => 'FirstName',
    'type' => 6, //You can specify direct see \fgh151\fields\FieldTypes
    'options' => [
        'variants' => [
            ['label' => 'var1', 'value' => 'var1'],
            ['label' => 'var2', 'value' => 'var2'],
            ['label' => 'var3', 'value' => 'var3'],
        ]
    ],
    'otherText' => 'Другое'
]);