Skip to content

Forms Builder Render Dynamic | Data in database

License

Notifications You must be signed in to change notification settings

YiiCollection/pceuropa_yii2-forms

 
 

Repository files navigation

FormBuilder module for Yii2

Latest Stable Version Total Downloads License

FormBuilder DEMO

Features

  1. Generate forms, surveys, polls, questionnaires (class FormBuilder)
  • Drag and drop - Sorting, editing, and deleting items
  • CRUD operations by AJAX
  • Built-in RBAC component
  1. Form render widget (class Form)
  • Validation forms (dynamic model)
  1. Storage data submited from form in databases
  • List of forms (GridView)
  • Create database tables after create form
  • Delete database tables after delete form
  • Add table column after add field to form
  • Rename table column after change the name of field
  • Drop table column after delete field in form

Installation Form Builder

composer require pceuropa/yii2-forms "dev-master"

Configuration Form Builder

Make sure that you have properly configured db application component in config file and run the following command:

$ php yii migrate/up --migrationPath=@vendor/pceuropa/yii2-forms/migrations

Add the following code in your configuration file:

'modules' => [
    'forms' => [
          'class' => 'pceuropa\forms\Module',
     ],
]

Usage

URLs for the translating tool:

/forms/module/index                    // List of all forms                     
/forms/module/user                     // List of user forms
/forms/module/view                     // Preview form
/forms/module/create                   // FormBuilder - create form
/forms/module/update                   // Update form 
/forms/module/delete                   // Delete form

Full example configuration Form Builder

'modules' => [
      'forms' => [
          'class' => 'pceuropa\forms\Module',
          'db' => 'db',
          'formsTable' => '{{%forms}}',
          'formDataTable' => 'form_', // dont use prefix please
          'sendEmail' => true, 
          'emailSender' => '[email protected]',
          'rules' => [
                [
                    'actions' => [ 'update', 'delete', 'clone'],
                    'allow' => true,
                    'roles' => ['updateOwnForm'],   // rule only owner can edit form
                ],
                [
                    'actions' => ['user', 'create'],
                    'allow' => true,
                    'roles' => ['user'],            // role only authenticated user can
                ]
            ]
      ]
],

Form renderer widget

use pceuropa\forms\Form;
echo Form::widget([
     'body' => '[[{"field": "input", "type": "text", "width": "col-md-5", "name": "email", "placeholder": "email"},{"field": "input", "name": "pass", "type": "text", "placeholder": "pass", "width": "col-md-5"},{"field": "submit", "width": "col-md-2", "backgroundcolor": "btn-info", "label": "Submit"}]]',
     'typeRender' => 'php'
     ]);

or

  echo Form::widget([
     'formId' => 1, // equivalennt 'form' => FormModel::findOne(1)->body
  ]);

Configure RBAC Component

Before you can go on you need to create those tables in the database.

yii migrate --migrationPath=@yii/rbac/migrations

Building autorization data

To use generator console, add fallowing code to config console file

'controllerMap' => [
  'formsrbac' => [
      'class' => 'pceuropa\forms\migrations\RbacController',
  ],
],

Create rbac tables in the database

yii migrate --migrationPath=@yii/rbac/migrations

Create rules and roles for form module

php yii formsrbac/generate

Tests

For tests run

composer exec -v -- codecept -c vendor/pceuropa/forms run

or

cd vendor/pceuropa/yii2-forms
codecept run

About

Forms Builder Render Dynamic | Data in database

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 61.9%
  • PHP 35.9%
  • CSS 2.0%
  • HTML 0.2%