简体   繁体   English

两个形式相同的输入冲突

[英]two inputs in same form are conflicting

I have a form that contains a table. 我有一个包含表格的表格。 Within each row of the table are two inputs. 该表的每一行中都有两个输入。 One of them is a text input to update the quantity of items in a cart. 其中之一是文本输入,用于更新购物车中的物品数量。 The other input is an image. 另一个输入是图像。 When clicked the item should be deleted. 单击时,应删除该项目。 If you update the amount in the text cell and hit return, it attempts to update it AND delete it. 如果您更新文本单元格中的金额并按回车键,它将尝试更新并删除它。 I've dumped the variables, and the $_POST array contains both the following entries: 我已经转储了变量,并且$ _POST数组包含以下两个条目:

KEY: summary KEY:总结

VAL: array(3) { ["ccbna007"]=> string(1) "5" ["ccbna001"]=> string(2) "10" ["ccbna002"]=> string(2) "10" } VAL:array(3){[“” ccbna007“] =>字符串(1)” 5“ [” ccbna001“] =>字符串(2)” 10“ [” ccbna002“] =>字符串(2)” 10“}

AND

KEY: delete KEY:删除

VAL: array(1) { ["ccbna007"]=> string(4) "-302" } VAL:array(1){[“” ccbna007“] => string(4)” -302“}

Can someone help me figure out how my markup is affecting my submitted variables, and in turn, how to fix the error? 有人可以帮我弄清楚我的标记如何影响我提交的变量,以及如何解决该错误? See the markup below. 请参阅下面的标记。 Please let me know if more information is needed. 请让我知道是否需要更多信息。

...inside a table within the form ...在表格内的表格内

<form action="distro.php" method="post">

    <tr>
    <td>S/T LP</td>
    <td><input type="text" value="10" name="summary[ccbna001]" size="2"></td>
    <td>10.00</td>
    <td>
      <a>
          <input alt="Remove item from your cart" type="image" title="Remove Item" src="img/delete.gif" name="delete[ccbna001]" height="10px" width="10px">

      </a>
    </td>
  </tr>

...More rows like this one... ...更多像这样的行...

</form>

If I were you I would do it like this: 如果我是你,我会这样做:

<form action="distro.php" method="post">
<table>
    <tr>
    <td>S/T LP</td>
    <td>
       <input type="text" value="10" name="summary[ccbna001]" size="2">
    </td>
    <td>10.00</td>
    <td>
      <a href="delete.php?id=123" id="delete[ccbna001]" >
          <img src="img/delete.gif" alt="Remove item from your cart" 
                height="10px" width="10px"/>
      </a>
    </td>
  </tr>
  <tr><td><input type="sumit" value="submit"></td></tr>
</table>
</form>

Because an image isnt an input, I would call a deleting script through the anchor tag. 因为图像不是输入,所以我将通过anchor标签调用删除脚本。

When you press enter , you are submitting all inputs as they fall under the same form. 当您按Enter时 ,您将提交所有输入,因为它们属于同一表格。 Make two forms and keep both inputs separate if you want them to be treated separately. 如果要分别对待两个输入,请制作两个表格并将两个输入分开。

Change the image input to simple image tag, then enclose it with link. 将输入的图像更改为简单图像标签,然后用链接将其括起来。 The link should guide to the script which will delete a row from your database or session. 该链接应指向该脚本,该脚本将从数据库或会话中删除一行。

You should have form for every row like this: 您应该为每一行都具有这样的表格:

<tr>
    <form action="distro.php" method="post">
        <td>S/T LP</td>
        <td><input type="text" value="10" name="summary[ccbna001]" size="2"></td>
        <td>10.00</td>
        <td>
            <a>
                <input alt="Remove item from your cart" type="image" title="Remove Item" src="img/delete.gif"
                       name="delete[ccbna001]" height="10px" width="10px">

            </a>
        </td>

        <input type="sumit" value="submit">
    </form>
</tr>

and so on for each row ... 以此类推...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM