POST data disappearing

POST data disappearing

pbercepberce Posts: 15Questions: 2Answers: 0
edited January 2013 in DataTables 1.9
I'm trying to POST back to my server to save edits. I use the method listed here:

http://www.datatables.net/release-datatables/examples/api/form.html

The problem is I'm only getting the first page of data, not the whole thing. I can see that sData has all the serialized data correctly (thank you FireBug), but, something is happening from that point to the point where I grab the $_POST data on the page reload.

I'm thinking it has something to do with the way I'm displaying my input fields, I'm hoping someone would have a suggestion on how I handle this.

I'm building my initial table by querying my database and building the table as follows:

[code]

$('#product_grid_form').submit( function() {
var sData = oTable.$('input').serialize();
} );

var oTable = $('#product_grid').dataTable();

...




column header
...
...



<?php
$results = mysql_query("SELECT * FROM example")
while ($row = mysql_fetch_array( $results );) {



...
...

}

?>



[/code]

Is this because I have live input elements on the page they are overriding the sData passed by Datatables? Is there a way around this?

The only thing I found that may work is the jQuery post method

[code]
$('#product_grid_form').submit( function() {
var sData = oTable.$('input').serialize();
$.post("save_sdata.php", sData, function(){ alert('success!'); });
return false;
} );
[/code]

If I am understanding this correctly the page would not reload, this would just push the data to the "save_sdata.php" page.

Any suggestions would be appreciated.

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    If the form is actually being allowed to submit, then you need to do one of:

    1. move the form input elements into the visible DOM
    2. show all rows
    3. inject new input elements in place of the hidden ones.

    Personally, if Ajax is acceptable, I'd use that route and so something like your last code block.

    Allan
  • pbercepberce Posts: 15Questions: 2Answers: 0
    Allan,

    Thanks for the reply, I'm working on using the Ajax method you mentioned and I have two issues.

    1. I just noticed that the

    [code]
    var sData = oTable.$('input').serialize();
    [/code]

    isn't finding all input elements in the table. This is only giving me the text fields, it is not finding the select or checkbox input elements.

    2. the page I am posting to only gets the first 1000 POST arguments, nothing more. I am sending ~3500 arguments in my POST. Do you know why this would happen? At first I thought that this may be a "post_max_size" php.ini issue, but, I doubled the limit and nothing changed, it still gets cut off at 1000. I'm looking at the data coming from the "oTable.$('input').serialize()" call and it has over 3500 elements, so I don't think that's the issue.

    Any suggestions would be appreciated.
  • pbercepberce Posts: 15Questions: 2Answers: 0
    One thing to add, php.ini max_input_vars was the solution for #2. Still not able to find out how to get all of the table elements.
  • pbercepberce Posts: 15Questions: 2Answers: 0
    Allan, one last update. I've solved all of my issues.

    The .serialize issue was simple to solve (though it took me several hours to see it)

    var sData = oTable.$(':input').serialize();

    add the : before the input to select all elements.

    The only negative to the .serialize method is it only recognizes the checkbox element if it's checked. If it's not checked it isn't added in the serialization process.
This discussion has been closed.