-1

So I've been tasked with crawling through a smallish PHP application to fix bugs and improve things where I can. 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. Problem is that it isn't getting set in the items array in $_POST, and I haven't any clue why.

As an example, here's a row in 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:

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

        )

I appreciate any and all suggestions!

Slippery John
  • 747
  • 2
  • 9
  • 20

2 Answers2

4

Remove the disabled="" attribute. Disabled inputs are not submitted when posting.

From the HTML specification

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.

Note: The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.

Community
  • 1
  • 1
Barmar
  • 741,623
  • 53
  • 500
  • 612
1

Try removing the disabled="" attribute in the hidden field.

OK11
  • 74
  • 3
  • `disabled="false"` will still disable it. The way to enable an element is to remove the attribute entirely. – Barmar Feb 14 '14 at 17:35
  • Thanks, updated answer. Seems like it could work if you do `disabled=false` because `disabled="false"` gets evaluated as true when parsed as a boolean. – OK11 Feb 14 '14 at 17:38
  • Attributes aren't parsed as booleans. Try it in jsfiddle. – Barmar Feb 14 '14 at 17:39
  • Isn't the disabled property a boolean property? – OK11 Feb 14 '14 at 17:51
  • See http://stackoverflow.com/questions/7089584/html-why-boolean-attributes-do-not-have-boolean-value – Barmar Feb 14 '14 at 17:53
  • Or better: http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#boolean-attributes: _The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether._ – Barmar Feb 14 '14 at 17:54
  • Thanks for the references; makes sense and I learned something! – OK11 Feb 14 '14 at 19:47