netcore/module-form

此包的最新版本(v1.3.2)没有提供许可证信息。

安装量: 1,182

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 7

分支: 0

公开问题: 2

类型:模块

v1.3.2 2018-08-13 16:42 UTC

README

本模块是为了方便管理自定义表单而制作的,例如联系表单、订阅表单等。

安装前

此包是Netcore CMS生态系统的一部分,并且仅在已安装以下包的项目中有效

  1. https://github.com/netcore/netcore
  2. https://github.com/netcore/module-admin
  3. https://github.com/netcore/module-translate

安装

  • 使用Composer安装此包
    composer require netcore/module-form
  • 发布 assets/configuration/migrations
    php artisan module:publish Form
    php artisan module:publish-config Form
    php artisan module:publish-migration Form
    php artisan migrate

配置

  • 配置文件位于 config/netcore/module-form.php

使用

  • 渲染表单
    app('forms')->replace('[form=(ID/Key)]');
    // or you can use helper method 
    form()->render('ID/Key');
  • 自定义模板
    If you want to render form with different template,
    you can create new file in /views/templates/forms (path can be changed in configuration),
    for example - contact-us.blade.php, where "contact-us" can be form key or the template name set when creating/editing form
  • 扩展表单提交功能
    // For example, if you want to send email to Administrator and/or User, who submitted the "Contact Us" form
    use Modules\Form\Repositories\FormsRepository;
    use Nwidart\Modules\Facades\Module;
    
    $module = Module::find('form');
    if ($module AND $module->enabled()) {
        FormsRepository::addNewEvent('contact-us', function ($data) {
            Mail::to('admin@example.com')->queue(new NotifyAboutContactMessage($data));
        });
    }
    // $data variable is array, which consists of submitted data, for example
    $data = [
        'name'      => 'John',
        'email'     => 'example@example.com',
        'message'   => 'Lorem ipsum.'
    ];