#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Shenandoah Valley, Virginia
    Posts
    220
    Rep Power
    53

    Error with form POST elements


    It's possible this belongs in the PHP forum, but I don't think my error is PHP-related. Feel free to correct me if I'm wrong. This may be a somewhat rambling post, and I apologize in advance.

    I'm working on a form so our data entry department can load datasets into mySQL. On the form, each row has 20 columns, all of which are single lines of text or dropdown boxes. There aren't any multi-line textfields, file uploads or anything like that, so it isn't really a lot of data.

    Using PHP to help generate the form, it starts off with 20 blank rows (similar to a small spreadsheet). In addition, once some rows are entered, whenever someone comes back to edit the dataset, you get 20 more blank rows. This is setup by a simple for($i=0;$i<20;$i++)

    The largest dataset that has been entered thus far has been about 15 rows, and I'd say that 10 ~ 20 rows would end up being the average that someone would input.

    However, now I have a problem. We just had a somewhat larger dataset come in that we needed to enter. It's about 35 rows. The data entry person entered some of the data, but when they went back to edit it and enter some new rows, it won't save. I turned on the PHP and mySQL errors and haven't had any issue there.

    I added print_r($_POST) and found that my "Save" submit button wasn't posting its value. After more study, with 35 rows of data, and 20 blank rows, I should be posting 55 total rows, so I'd expect my last array element to be numbered 54 since it starts with zero.

    However in the POST array, the first 10 or so fields have array elements up to 52, and the next 10 or so fields only have array elements up to 51.

    For testing purposes, I adjusted the number of blank rows that should be added to the bottom of the form up to 100 and re-loaded the page. I do get 100 blank rows on my screen after the 34 rows that have been entered, but when I submit the page and view the $_POST data, instead of the 134 elements I'd expect, it still only shows that I posted up to element 52.

    I think the error is definitely dependent on the number of rows as opposed to any data validation errors, because i can adjust the form to only have 3 blank rows after the data set, and it'll post all 37 form elements just fine without issue and save the data. Element 51~52 seems to be the cutoff.

    Any suggestions? Does this post make a bit of sense? Is there a maximum post size as far as the number of elements? In PHP I tried setting memory_limit to 512M and post_max_size to 400M (which is WAY more than I'd need) and no change, so I'd think it has something to do with the HTML elements or Apache's config. If a snippet of the data would be helpful, please let me know.
    Last edited by SlinginSam; May 24th, 2012 at 02:34 PM.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,296
    Rep Power
    7170
    There is no limit on the number of elements you can submit. If PHP's post limit was exceeded $_POST would be empty. If PHP's memory limit was exceeded you would get a fatal error.

    It's possible that you have some sort of HTML error that causes some fields to be missing. Use an HTTP request viewer like HTTPFox or Firebug to inspect the HTTP request that is sent to the server when you submit your form. See whether or not it contains all of the fields you expect it to. If it does, the server might be truncating your response. If it doesn't, then there is probably an HTML error somewhere on your page (like mismatched quotes or brackets).

    Comments on this post

    • SlinginSam agrees : Thanks for your help.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Shenandoah Valley, Virginia
    Posts
    220
    Rep Power
    53
    Originally Posted by E-Oreo
    Use an HTTP request viewer like HTTPFox or Firebug to inspect the HTTP request that is sent to the server when you submit your form. See whether or not it contains all of the fields you expect it to. If it does, the server might be truncating your response. If it doesn't, then there is probably an HTML error somewhere on your page (like mismatched quotes or brackets).
    I've used Firebug only sporadically so I had to Google how to do exactly what you asked. I checked the values on the form, and I can confirm that they are all being sent to the server via the POST request. If the server is indeed truncating the response (which does seem to be the case since the only variable is the number of rows) how would I go about troubleshooting that?

    Thanks for the assistance.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Shenandoah Valley, Virginia
    Posts
    220
    Rep Power
    53
    Just for a slight bit of more detail, the code checks that the submit button has been clicked and that's when it knows to save the results.

    The submit button it named "save_list_segment" and the value is "Save List Segment".

    When I click to save the form when i have approx 50 or less rows, and use print_r($_POST) on the results page, I get the expected result ($_POST['save_list_segment'] is equal to 'Save List Segment')

    If I add more a few more blank rows and I do the same test, it doesn't even show that the "save_list_segment" value was submitted to the server. According to the results page there isn't a $_POST['save_list_segment'] variable at all.

    It should be getting there though, because in Firebug, no matter the quantity of rows, in the POST section is does show:

    save_list_segment = Save List Segment
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Shenandoah Valley, Virginia
    Posts
    220
    Rep Power
    53
    I reviewed the Apache error logs for today, as well as the SuExec and SuPHP for good measure, and aside from the occassional 404 on a missing favicon, I don't really see anything noteworthy.
  10. #6
  11. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,296
    Rep Power
    7170
    In Apache the LimitRequestBody would be used to limit the size of a POST body. However, this is unlimited in a default configuration.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Shenandoah Valley, Virginia
    Posts
    220
    Rep Power
    53
    I checked httpd.conf and didn't find any references to LimitRequestBody. I'm running a grep search now to make sure it's not in any .htaccess files or anything like that.

    I did just find out some more interesting information. After looking more into PHP's documentation on POST data, I ran this code at the top of my page and printed the results:
    Code:
    file_get_contents("php://input");
    All of the POST data is contained here successfully. Nothing is missing. Yet if I print_r($_POST) on the same page, some of the array values are missing.

    For example, the end of the raw post data says:
    Code:
    &save_list_segment=Save+List+Segment
    but when I run

    Code:
    echo $_POST['save_list_segment']
    the value is blank...
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2003
    Location
    Shenandoah Valley, Virginia
    Posts
    220
    Rep Power
    53

    Success!


    Armed with this new bit of information, I was able to find someone that had an error very close to mine. It actually ended up being a PHP issue after all, or rather a configuration issue in Suhosin. The array keys and values were missing once you got over ~1,020 elements.

    I went into php.ini and adjusted the value of suhosin.post.max_vars (and for good measure suhosin.request.max_vars) to 5,000 from their installed default of 1,000 and the issue seems to be solved. Hopefully someone else with the same problem can benefit from this post. Please feel free to move it to the PHP forum if you think that best. Thanks again for your suggestions.

IMN logo majestic logo threadwatch logo seochat tools logo