Можно ли вывести бэкэнд-форму во внешний интерфейс? - PullRequest
0 голосов
/ 30 апреля 2019

Можно ли вывести поля (fields.yaml) из бэкэнд-формы какой-либо модели во внешний интерфейс?

Ответы [ 2 ]

0 голосов
/ 15 мая 2019

Может быть, это вариант

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

"Компоненты для создания всех внутренних виджетов на страницах внешнего интерфейса (списки, поиск, фильтр, формы, виджеты форм, MediaManager, отчеты) и управления этими элементами"

0 голосов
/ 30 апреля 2019

Решение: Необходимо создать компонент:

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>
...