【问题标题】:Is it possible to output backend form into frontend?是否可以将后端表单输出到前端?
【发布时间】:2019-09-19 00:56:22
【问题描述】:

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

【问题讨论】:

  • 您能出示您的代码吗?
  • 没有一些代码。谁知道OctoberCMS会明白

标签: laravel octobercms


【解决方案1】:

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

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>

【讨论】:

    【解决方案2】:

    也许这是一个选择

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

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

    【讨论】:

      猜你喜欢
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-16
      • 2012-10-09
      • 1970-01-01
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      相关资源
      最近更新 更多