2014-02-06 23 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

非常欢迎。祝你好运! –

相关问题