是否可以将某些模型的后端形式的字段(fields.yaml)输出到前端?
答案 0 :(得分: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>
答案 1 :(得分:0)
也许这是一个选择
https://octobercms.com/plugin/linkonoid-backtofront
“用于在前端页面中创建所有后端窗口小部件(列表,搜索,过滤器,表单,FormWidget,MediaManager,报表)并管理此项目的组件”