是否可以将后端表单输出到前端?

问题描述 投票:-5回答:2

是否可以将字段(fields.yaml)从某些模型的后端形式输出到前端?

laravel octobercms
2个回答
0
投票

解决方案:需要创建组件:

use Cms\Classes\ComponentBase;

class someForm extends ComponentBase
{
    public function componentDetails()
    {
        return [
            'name' => 'Some Form',
            'description' => 'Backend form used in the front-end'
        ];
    }

    public function onRun()
    {
      // to make scripts work (like hide/show some field on changing another)
      $this->addJs("/modules/system/assets/ui/storm-min.js");
      // optional. The form will look like in backend
      // $this->addCss("/modules/system/assets/ui/storm.css");

      $formController = new \Author\Plugin\Controllers\Forms();
      $formController->create('frontend');
      // Append the formController to the page
      $this->page['form'] = $formController;
    }

    public function onSave()
    {
        return ['error' => \Author\Plugin\Models\Form::create(post('Entry'))];
    }
}

这个组件的default.htm

{% put styles %}
// add this style only if you didn't include storm.css
<style>
    .hide {
        display: none!important;
    }
</style>
{% endput %}

<div class="confirm-container bg-success hide">
  <p>New entry was succesfuly added!</p>
</div>


<form role="form"
  data-request="{{ __SELF__ }}::onSave"
  data-request-success="$el.hide();$('.confirm-container’).removeClass('hide’);">

  {{ form.formRender()|raw }}

  <div class="form-group">
     <button class="btn btn-primary btn-block btn-lg" type="submit" value="register">Create</button>
  </div>
</form>

0
投票

也许这可能是一个选择

https://octobercms.com/plugin/linkonoid-backtofront

“用于在前端页面(列表,搜索,过滤器,表单,FormWidgets,MediaManager,报告)中创建所有后端窗口小部件并管理此项目的组件”

© www.soinside.com 2019 - 2024. All rights reserved.