mhunesi/yii2-formio

Yii2 Formio 扩展

安装次数: 499

依赖者: 0

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 1

类型:yii2-extension

v0.0.1 2020-04-28 00:25 UTC

This package is auto-updated.

Last update: 2024-09-27 13:59:04 UTC


README

Yii Formio 模块


Form.io 插件的软件包集合。Form.io 是一个纯 JavaScript 表单渲染器。

使用 JSON 表单构建器驱动的表单 https://formio.github.io/formio.js

示例

安装

将包添加到您的 composer 文件中

composer require mhunesi/yii2-formio

您需要做的最后一件事是通过应用迁移来更新您的数据库模式。确保您已正确配置 db 应用组件,并运行以下命令:

    yii migrate --migrationPath=@mhunesi/formio/migrations

将模块添加到您的应用程序配置文件中

'modules' => [
    // ...
    'formio' => [
        'class' => \mhunesi\formio\Module::class,
        'userModel' => 'app/models/User'
    ],
    // ...
]

用法

如果您只想使用 Formio 小部件

<?= FormioWidget::widget([
    'id' => 'example',
    'action' => Url::to(['example/create']),
    'thanksPage' => Url::to(['example/create']),
    'submission' => [
        'firstName' => 'Mustafa'
    ],
    'query' => [
        'components' => [
            [
                'type' => 'textfield',
                'key' => 'firstName',
                'label' => 'First Name',
                'placeholder' => 'Enter your first name.',
                'input' => true,
                'tooltip' => 'Enter your <strong>First Name</strong>',
                'description' => 'Enter your <strong>First Name</strong>',
            ],
            [
                'type' => 'button',
                'action'  => 'submit',
                'label' => 'Submit',
                'theme' => 'primary'
            ]
        ]
    ],
    'clientOptions' => [
        'hooks' => [
            'beforeSubmit' => new JsExpression("
                (submission, next) => {
                    if(confirm('Are you sure?')){
                        next();
                    }
                }"
            )
        ]
    ]

]) ?>

或者您可以使用 Form.io 构建器并

$form = Forms::findOne(8);

$form->render([
    'thanksPage' => Url::to(['example/thanks']),
]);

截图

screen-1

所有截图...

mhunesi 构建