Missing array values using fnGetHiddenNodes function.

Missing array values using fnGetHiddenNodes function.

Bjorn_Bjorn_ Posts: 1Questions: 1Answers: 0

Hi Guys,

I'm new to PHP and i just discovered the DataTables plugin, i think it's awesome!
I'm working on a project where i use this plugin within a html form, to display data and let the user input a value using an input field.
Within the form i use another input field with the attribute 'hidden' to store an id value (product id).

When submitting the form i use the fnGetHiddenNodes() function to retrieve user inputs on the pages that are not being displayed.
It all works fine, but somehow i'm missing "id"'s when i submit the form WITH this hidden input field.
When i submit the form using only the quantity input field it all works fine...

  • The data is retrieved through the PDO interface sqlsrvr.

Any thoughts?, here is some code...

DataTables initialize and fnGetHiddenNodes()

` <script type="text/javascript" charset="utf-8">

    jQuery.fn.dataTableExt.oApi.fnGetHiddenNodes = function ( settings )
    {
        var nodes;
        var display = jQuery('tbody tr', settings.nTable);
        var api = new jQuery.fn.dataTable.Api( settings );
        nodes = api.rows().nodes().toArray();
        /* Remove nodes which are being displayed */
        for ( var i=0 ; i<display.length ; i++ ) {
            var iIndex = jQuery.inArray( display[i], nodes );
            if ( iIndex != -1 ) {
            nodes.splice( iIndex, 1 );
            }
        }
        return nodes;
    };

    $(document).ready(function() {

        var oTable = $('#example').dataTable({
          "bSort": false
        });

        $('#button').click( function () {
        var form = $('#form');
        var nHidden = oTable.fnGetHiddenNodes();

        $(nHidden).appendTo(form);
        form.submit();
        } );
    });
</script>`

HTML & PHP to echo value from $row id.

` <form id="form" method="post" action="order.php">
<table id="example" class="display" cellspacing="0" width="100%">

               echo "<tr>";
                echo "<td> <input type='number' name='quantity[]'></td>";
                echo "<td> <input type='number' name='id[]' value='", $row['@@RRNO'],"'></td>";
                echo "</tr>";

</table>
<input type="submit">
</form>
`

-note-the-687-entries.">-note-the-687-entries." href="#Output-->-note-the-687-entries.">Output -> note the 687 entries.

see image of printscreen

On the php side to get array values

$array=array_values($_POST['id']); print_r($array);

-note-only-498-array-values-(indexes)">-note-only-498-array-values-(indexes)" href="#Output-->-note-only-498-array-values-(indexes)">Output -> note only 498 array values (indexes)

see second image of printscreen

This discussion has been closed.