I have a form in the back-end to create new entries. I want to allow my website's front-end users to create these entries as well, so since I already have such form and the controller in the back-end, I'd like to utilize it in the front-end as well.
I've created a component for the front-end and tried to render the back-end form in it, like so:
# components/NewEntryForm.php
<?php namespace Author\PluginName\Components;
use Cms\Classes\ComponentBase;
use Author\PluginName\Models\Entry;
use Author\PluginName\Controllers\Entries as EntryController;
class NewEntryForm extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'NewEntryForm Component',
'description' => 'No description provided yet...'
];
}
public function onRun()
{
// New back-end form with the context of 'frontend'
$formController = new EntryController();
$formController->create('frontend');
// Append the entryController to the page
$this->page['form'] = $formController;
// Add backend styles to the form
$this->addCss('/modules/backend/assets/css/controls.css', 'core');
}
}
Component's default.htm
:
<!-- components/newentryform/default.htm -->
<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>
However, I get the following error:
An exception has been thrown during the rendering of a template ("The partial '_field_richeditor.htm' is not found.").
You need to
resister
thosewidgets manually
, as inbackend
they areregistered by backend provider
.if any doubts please comment.