简体   繁体   English

表单数组的隐藏元素未在PHP中设置

[英]Hidden element of a form array is not getting set in PHP

So I've been tasked with crawling through a smallish PHP application to fix bugs and improve things where I can. 因此,我的任务是通过一个很小的PHP应用程序进行爬网,以修复错误并在可能的地方进行改进。 One thing I noticed was that updates were not updates, they were deletes+inserts, so I'm doing what I can to remedy that. 我注意到的一件事是,更新不是更新,它们是删除+插入,因此我正在尽力解决这一问题。

To that end, I've added a hidden element to each row of a large table of items which will contain the id of said item so that I know what to update. 为此,我在大型项目表的每一行中添加了一个隐藏元素,其中包含该项目的ID,以便我知道要更新的内容。 Problem is that it isn't getting set in the items array in $_POST , and I haven't any clue why. 问题是它没有在$_POST的items数组中设置,我也不知道为什么。

As an example, here's a row in HTML: 例如,下面是HTML中的一行:

<div class="row">
  <div class="c item_index"><sub>1</sub></div>
  <input type="hidden" name="ordered_items[1][id]" id="item_id1" value="9" disabled="">
  <div class="c qty">
    <input type="text" name="ordered_items[1][quantity]" id="quantity1" value="12">
  </div>
  <div class="c vendor_num">
    <input type="text" name="ordered_items[1][vendor_number]" id="vendor_num1" value="">
  </div>
  <div class="c item_desc">
    <input type="text" name="ordered_items[1][description]" id="desc1" value="12">
  </div>
  <div class="c cost_per">
    <input type="text" name="ordered_items[1][cost_per]" id="cost1" value="12.00">
  </div>
  <div class="c total">
    <input type="text" name="ordered_items[1][total]" class="total" placeholder="0.00"
           id="total1" value="144.00" readonly="">
  </div>
</div>

Here's it's entry in $_POST : 这是$_POST的条目:

[ordered_items] => Array
        (
            [1] => Array
                (
                    [quantity] => 12
                    [vendor_number] => 
                    [description] => 12
                    [cost_per] => 12.00
                    [total] => 144.00
                )

        )

I appreciate any and all suggestions! 我感谢所有建议!

Remove the disabled="" attribute. 删除disabled=""属性。 Disabled inputs are not submitted when posting. 发布时不提交禁用的输入。

From the HTML specification HTML规范

A number of attributes are boolean attributes. 许多属性是布尔属性。 The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value. 元素上的布尔属性的存在表示真实值,而该属性的缺失表示错误值。

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace. 如果存在该属性,则其值必须为空字符串或该属性的规范名称的ASCII大小写不匹配的值,且没有前导或尾随空格。

Note : The values "true" and "false" are not allowed on boolean attributes. 注意 :布尔属性上不允许使用值“ true”和“ false”。 To represent a false value, the attribute has to be omitted altogether. 为了表示一个假值,必须完全省略该属性。

尝试删除隐藏字段中的disabled=""属性。

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

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