【问题标题】:One form with two image buttons is sending both values of the buttons when only one can be pressed一种具有两个图像按钮的表单在只能按下一个时发送按钮的两个值
【发布时间】:2016-05-07 20:39:20
【问题描述】:

我正在尝试从表单发送数据,在此表单中有 2 个图像按钮。其中一个按钮保存数据,而另一个按钮将其发送到另一个表单。问题是当我按下任一图像按钮时,“saveData”和“saveData”值都会被发送。

这些隐藏的输入通过我按下的任一图像按钮发送。

<input type="hidden" name="saveData" value="2">
<input type="hidden" name="sendData" value="3">

我用 var_dump 检查了我得到了什么,两个变量都被发送了。

//var_dump($this->input->post(NULL, TRUE));
  'saveData' => string '2' (length=1)
  'sendData' => string '3' (length=1)

<td rowspan="2" align="center">
    <a href="javascript:void(0);" onclick="javascript:document.forms['form1'].submit();">
        <img src="<?php echo base_url(); ?>images/save.png" alt="Save Data" width="30" height="30" />
        <input type="hidden" name="saveData" value="2">
    </a>
    <br />
&nbsp;&nbsp;Save  

 <!-- The user pressed the icon to send the data so it will now have to save that the user decided to do this in the database a Boolean in the database  
still the view. -->

</td>
<td rowspan="2" align="center">
    <a href="javascript:void(0);" onclick="javascript:document.forms['form1'].submit();">
        <img src="<?php echo base_url(); ?>images/save.png" alt="Send Data" width="30" height="30" />
        <input type="hidden" name="sendData" value="3">
    </a>
    <br />
&nbsp;&nbsp;Send
</td>
</form>

【问题讨论】:

    标签: javascript php forms


    【解决方案1】:

    当然,当发送表单时,所有隐藏的输入也会被发送。 你可以做的很简单:

    <style>
    .ibtn {
      border:none;
      padding:0;
    }
    .ibtn::-moz-focus-inner {
      padding: 0;
      border: 0
    }
    </style>
    
    <form>
      <button class="ibtn" name="send" value="1"><img src="http://www4.dict.cc/img/but_speech.gif"></button>
      <button class="ibtn" name="send" value="2"><img src="http://www4.dict.cc/img/but_speech.gif"></button>
    </form>
    

    另一种选择是将两个表格分开,每个表格都有自己的数据。

    【讨论】:

    • 我在一页中有两个表格。那么我如何指定我与您的答案一起发送的表格
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-20
    • 2015-07-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 2020-04-30
    • 2022-07-16
    相关资源
    最近更新 更多