PHP一个表单多个提交按钮解决方法

时间:2021-03-14 19:29:53

1、html页面<注:多个按钮的name值必须相同>

<form action="{:U('Index/index')}" method="post" >
                <div class="search-tj">
                    <span>
                        <input class="search-sub" type="submit" value="添加" id="tj" name="inputs">
                    </span>
                </div>
                <div class="search-tj">
                    <span><input class="search-txt" type="text" name="input" value="{$input}" placeholder="请输入昵称或手机号" />
                        <input class="search-sub" type="submit" value="搜索" id="ss" name="inputs"></span>
                </div>
            </form>           

2、PHP页面

 if($_POST){
            $nval = $_POST['inputs'];
            if($nval=='添加'){
                echo "添加";
            }else{
                echo "搜索";
            }
        }

 

<form action="{:U('Index/index')}" method="post" >
<div class="search-tj">
<span>
<input class="search-sub" type="submit" value="添加" id="tj" name="inputs">
</span>
</div>
<div class="search-tj">
<span><input class="search-txt" type="text" name="input" value="{$input}" placeholder="请输入昵称或手机号" />
<input class="search-sub" type="submit" value="搜索" id="ss" name="inputs"></span>
</div>
</form>