2017 © Pedro Peláez
 

yii2-extension yii2-form-builder

Small and easy form builder

image

metalguardian/yii2-form-builder

Small and easy form builder

  • Sunday, March 6, 2016
  • by MetalGuardian
  • Repository
  • 8 Watchers
  • 15 Stars
  • 5,290 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 11 Forks
  • 0 Open issues
  • 3 Versions
  • 52 % Grown

The README.md

Yii2 Form Builder

Small and easy form builder. You can store form configuration in form model., (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

Scrutinizer Code Quality Code Coverage Build Status Code Climate, (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist metalguardian/yii2-form-builder "~1.0"

or add, (*6)

"metalguardian/yii2-form-builder": "~1.0"

to the require section of your composer.json file., (*7)

Usage

First of all you need write form config (you can store it in model class), (*8)

<?php

namespace app\models;

use metalguardian\formBuilder\ActiveFormBuilder;

/**
 */
class Example extends \yii\db\ActiveRecord
{
    .....
    /**
     * @return array
     */
    public function getFormConfig()
    {
        return [
            'label' => [
                'type' => ActiveFormBuilder::INPUT_TEXT,
            ],
            'content' => [
                'type' => ActiveFormBuilder::INPUT_TEXTAREA,
                'hint' => 'hint about field',
            ],
            'type' => [
                'type' => ActiveFormBuilder::INPUT_DROPDOWN_LIST,
                'items' => [1 => 'One', 2 => 'Two'],
                'options' => [
                    'prompt' => 'select',
                ],
            ],
            'published' => [
                'type' => ActiveFormBuilder::INPUT_CHECKBOX,
            ],
            'redactor' => [
                'type' => ActiveFormBuilder::INPUT_WIDGET,
                'widgetClass' => \vova07\imperavi\Widget::className(),
            ],
            'raw_data' => [ // need to define attribute `raw_data` in model 
                'type' => ActiveFormBuilder::INPUT_RAW,
                'value' => 'raw html data',
            ],
        ];
    }
}

Now in form view you can write something like this:, (*9)

.....
<?php $form = \metalguardian\formBuilder\ActiveFormBuilder::begin(); ?>


<?= $form->renderForm($model, $model->getFormConfig()) ?>

<div class="form-group">
    <?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
</div>

<?php \metalguardian\formBuilder\ActiveFormBuilder::end(); ?>
.....

Advanced Usage

You can define configuration of different elements in model, (*10)

<?php

namespace app\helpers;

use metalguardian\formBuilder\ActiveFormBuilder;

/**
 */
class Helper
{
    .....
    /**
     * @return array
     */
    public static function getLabelConfig()
    {
        return [
            'type' => ActiveFormBuilder::INPUT_TEXT,
        ];
    }

    /**
     * @return array
     */
    public static function getContentConfig()
    {
        return [
            'type' => ActiveFormBuilder::INPUT_TEXTAREA,
        ];
    }
}

Now you can use different models in one form, (*11)

.....
<?php $form = \metalguardian\formBuilder\ActiveFormBuilder::begin(); ?>

<?= $form->renderField($model1, 'label', \app\helpers\Helper::getLabelConfig()); ?>
<?= $form->renderField($model1, 'content', \app\helpers\Helper::getContentConfig()); ?>

<?= $form->renderField($model2, 'label', \app\helpers\Helper::getLabelConfig()); ?>
<?= $form->renderField($model2, 'content', \app\helpers\Helper::getContentConfig()); ?>

<div class="form-group">
    <?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
</div>

<?php \metalguardian\formBuilder\ActiveFormBuilder::end(); ?>
.....

The Versions

06/03 2016

dev-master

9999999-dev

Small and easy form builder

  Sources   Download

MIT

The Requires

 

by Ivan Pushkin

extension yii2 form builder

06/03 2016

1.0.1

1.0.1.0

Small and easy form builder

  Sources   Download

MIT

The Requires

 

by Ivan Pushkin

extension yii2 form builder

28/02 2015

1.0.0

1.0.0.0

Small and easy form builder

  Sources   Download

MIT

The Requires

 

by Ivan Pushkin

extension yii2 form builder