2017-02-16 80 views
0

在Prestashop後臺中,我創建了一個帶有標籤爲「保存」的提交按鈕的表單。是否可以添加另一個提交按鈕以執行不同的操作?是否可以在一個表單中有兩個提交按鈕?

+0

http://stackoverflow.com/questions/16162972/more-than-one-submit-button –

+0

[多於一個的提交按鈕(的可能的複製http://stackoverflow.com/questions/16162972 /更比一提交按鈕) –

回答

0

要完成您所需要的操作,您不應將多個操作綁定到同一個Form Helper,而只需爲爲Helper定義的每個不同的提交輸入類型指定一個不同的名稱。

0

只是檢查form.tpladmin/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類型可以是「提交」和如果你的按鈕定義了'name',那麼在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); 

} 
相關問題