在 Prestashop 后台我创建了一个带有标记为“保存”的提交按钮的表单。是否可以添加另一个具有不同操作的提交按钮?
问问题
888 次
2 回答
2
form.tpl
在那里检查admin/themes/default/template/helpers/form/
你会发现部分
{if isset($fieldset['form']['buttons'])}
{foreach from=$fieldset['form']['buttons'] item=btn key=k}
{if isset($btn.href) && trim($btn.href) != ''}
<a href="{$btn.href}" {if isset($btn['id'])}id="{$btn['id']}"{/if} class="btn btn-default{if isset($btn['class'])} {$btn['class']}{/if}" {if isset($btn.js) && $btn.js} onclick="{$btn.js}"{/if}>{if isset($btn['icon'])}<i class="{$btn['icon']}" ></i> {/if}{$btn.title}</a>
{else}
<button type="{if isset($btn['type'])}{$btn['type']}{else}button{/if}" {if isset($btn['id'])}id="{$btn['id']}"{/if} class="btn btn-default{if isset($btn['class'])} {$btn['class']}{/if}" name="{if isset($btn['name'])}{$btn['name']}{else}submitOptions{$table}{/if}"{if isset($btn.js) && $btn.js} onclick="{$btn.js}"{/if}>{if isset($btn['icon'])}<i class="{$btn['icon']}" ></i> {/if}{$btn.title}</button>
{/if}
{/foreach}
{/if}
如您所见,您可以定义用户定义按钮的数组
<button type="{if isset($btn['type'])}{$btn['type']}{else}button{/if}"...
如果此处类型可以是“提交”,并且如果为您的按钮定义了“名称”,那么在 postProcess() 中,您可以为 hepler 表单中的附加提交类型按钮做您的事情。
铁
public function renderForm() {
$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');
$fields_form = array();
$fields_form[0]['form'] = array(
'legend' => array(
... legend part...
),
'input' => array(
...arrays of inputs...
),
'submit' => array(
...default submit button...
),
'buttons' => array(
'0' => array(
'type' => 'submit',
'title' => $this->l('Whatever'),
'name' => 'MySubmitName',
'icon' => 'process-icon-back',
'class' => 'pull-right',
)
)
);
$helper = new HelperForm();
// Module, token and currentIndex
$helper->token = Tools::getAdminTokenLite('AdminYourClassName');
$helper->currentIndex = self::$currentIndex;
// Language
$helper->default_form_language = $default_lang;
$helper->allow_employee_form_lang = $default_lang;
// Title and toolbar
$helper->show_toolbar = false;
$helper->submit_action = 'submitWhatever';
return $helper->generateForm($fields_form);
}
于 2017-08-01T06:55:28.033 回答
0
要完成您需要的工作,您不应将多个操作绑定到同一个表单助手,而只需为助手定义的每个不同的提交输入类型指定一个不同的名称。
于 2017-02-23T05:04:58.053 回答