#
Form Draft
1.0.7+ | 1.1.2+
#
Basic usage
#
Template example:
<xf:comment>The JavaScript inclusion below is only required for XenForo versions prior to 2.3.0</xf:comment>
<xf:js src="TC/ComponentLibrary/form.js" addon="TC/ComponentLibrary" min="1" />
<xf:form class="block"
data-xf-init="tc-form-draft"
data-draft-save-url="{{ link('demo/form-draft/save') }}"
data-draft-load-url="{{ link('demo/form-draft/load') }}">
<div class="block-container">
<div class="block-body">
<xf:textboxrow label="Test 1"
name="test1" />
<xf:textboxrow label="Test 2"
name="test2" />
<xf:textboxrow label="Test 3"
name="test3" />
</div>
<xf:submitrow icon="save">
<xf:html>
<xf:macro id="tc_clib_form_draft_macros::controls"
arg-menuHref="{{ link('demo/form-draft/menu') }}" />
</xf:html>
</xf:submitrow>
</div>
</xf:form>
#
Controller example:
<?php
namespace MV\Playground\Pub\Controller;
use TC\ComponentLibrary\ControllerPlugin\FormDraft;
use XF\Mvc\Reply\AbstractReply;
use XF\Pub\Controller\AbstractController;
class Demo extends AbstractController
{
public function actionIndex(): AbstractReply
{
return $this->view(
'Vendor\AddOn:Demo\FormInputs',
'demo_form'
);
}
public function actionFormDraftMenu(): AbstractReply
{
/** @var FormDraft $formDraftPlugin */
$formDraftPlugin = $this->plugin('TC\ComponentLibrary:FormDraft');
return $formDraftPlugin->actionMenu('demo');
}
public function actionFormDraftLoad(): AbstractReply
{
/** @var FormDraft $formDraftPlugin */
$formDraftPlugin = $this->plugin('TC\ComponentLibrary:FormDraft');
return $formDraftPlugin->actionLoad('demo');
}
public function actionFormDraftSave(): AbstractReply
{
/** @var FormDraft $formDraftPlugin */
$formDraftPlugin = $this->plugin('TC\ComponentLibrary:FormDraft');
return $formDraftPlugin->actionSave('demo');
}
}
#
TC\ComponentLibrary\ControllerPlugin\FormDraft
#
actionMenu
Returns a response containing the contents of a menu listing the user's drafts for the specified form.
public function actionMenu(string $formKey, string $draftEntity = null, string $viewClass = null, string $template = null, array $params = []): AbstractReply
#
Параметры
#
actionLoad
Returns a JSON response with an object containing the values of the $draftEntity entity with the ID specified by
the draft_id parameter.
public function actionLoad(string $formKey, string $draftEntity = null): AbstractReply
#
actionSave
Updates the title and draft_data columns of the $draftEntity entity with the ID specified by the draft_id
parameter with the values from the parameters of the same name. If the delete parameter is set to true, the entity
will be deleted.
After saving, a JSON response is returned with an object containing the values of the updated $draftEntity.
After deleting, only the ID of the deleted entity is returned.
public function actionSave(string $formKey, string $draftEntity = null): AbstractReply
#
See also
JavaScript / Form / Form Draft.