2014-02-06 27 views
0

我有型的兩個按鈕提交在我view如何知道哪個按鈕提交表單的PHP

<button type="submit" class="btn btn-default btn-xs" name="Excel"> 
    <span class="glyphicon glyphicon-download-alt"></span>&nbsp; Download as Excel 
</button> 

<button type="submit" class="btn btn-default btn-xs" name="Resume"> 
    <span class="glyphicon glyphicon-download-alt"></span>&nbsp; Download Resume 
</button> 

controller

if ($this->input->post('Resume')) { 
    echo "Resume Clicked"; 
} 

if ($this->input->post('Excel')) { 
    echo "Excel Clicked"; 
} 

我想知道哪個按鈕提交表單爲我寫了上面的代碼..但我沒有得到任何echo點擊任何按鈕後..

我不想使用在這裏:

<input type='submit' name='excel' value='Excel'/>

<input type='submit' name='excel' value='Excel'/>

因爲它與類型 '輸入' 的作品我想使用的typesubmit

+0

你爲什麼不想用''? –

+0

@BrianWarshaw因爲我用於鍵入按鈕的CSS ....以及我得到我的解決方案非常感謝你 –

回答

0

button值添加到該按鈕,即:

<button type="submit" class="btn btn-default btn-xs" name="Resume" value="true"> 
    <span class="glyphicon glyphicon-download-alt"></span>&nbsp; Download Resume 
</button> 

您將有一個值爲「true」的$ _POST ['Resume']在你的後端代碼中。

當然是這樣的:name="buttonName" value="Excel"name="buttonName" value="Resume"的另一個按鈕將會產生一個$_POST['buttonName'],其值可以是'Excel'或'Resume'。

+0

非常感謝你的工作像魅力!.... –

+1

非常歡迎。祝你好運! –

相關問題