一个表单中可以有两个提交按钮吗?

问题描述 投票:0回答:2

在 Prestashop 后台,我创建了一个表单,其中一个提交按钮标记为“保存”。是否可以添加另一个具有不同操作的提交按钮?

form-data submit-button prestashop-1.7
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 形式为附加提交类型按钮做一些事情。

f.e.

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);

}

0
投票

要完成您的需要,您不应将多个操作绑定到同一个表单助手,而只需为为助手定义的每个不同的提交输入类型指定不同的名称。

© www.soinside.com 2019 - 2024. All rights reserved.