是否可以在一个表单中有两个提交按钮?

时间:2017-02-16 10:41:12

标签: form-data submit-button prestashop-1.7

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

2 个答案:

答案 0 :(得分:1)

只需检查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}"...

Wehere类型可以提交&#39;如果&#39; name&#39;对于您定义的按钮,然后在postProcess()中,您可以以肝脏形式为您的其他提交类型按钮执行操作。

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

}

答案 1 :(得分:0)

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