1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Submit Large Form Arrays Problem

Discussion in 'PHP' started by greatlogix, May 20, 2014.

  1. #1
    I have a page where i have listed more than 100 products on page and user can submit many product attributes like size, weight, list price, discount price, wholesale price...etc. I am using form arrays to submit this huge data. I am not getting complete form data after submit. print_r showing only 81 form elements submitted, all other are ignored. post_max_size is 10MB so I am sure its not the reason behind it. Can you please help me on this issue.
     
    Solved! View solution.
    greatlogix, May 20, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Show us some code, perhaps? Are you using POST or GET?
     
    PoPSiCLe, May 20, 2014 IP
  3. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    POST.
    <tr>
                    <td> </td>
                    <td>Product Name                    <input type="hidden" name="bId[]" value="30844">
                    </td>
                    <td><input name="lp[]" type="text" class="txtText" id="lp[]" value="26.99" size="7"></td>
                    <td><input name="dp[]" type="text" class="txtText" id="dp[]" value="17.99" size="7"></td>
                    <td><input name="wp[]" type="text" class="txtText" id="wp[]" size="7" value="10.00"></td>
                    <td>
                    <input name="trm[]" type="text" class="txtText" id="trm[]" size="7" value="7.85">                </td>
                    <td><input name="si[]" type="text" class="txtText" id="si[]" value="28x52" size="9"></td>
                    <td><input name="pcode[]" type="text" class="txtText" id="pcode[]" value="c-W836" size="7" maxlength="20"></td>
                    <td><input name="lbs[]" type="text" class="txtText" id="lbs[]" value="0" size="7" maxlength="20"></td>
                    <td><input name="oz[]" type="text" class="txtText" id="oz[]" value="9" size="7" maxlength="20"></td>
                    <td><input name="stock[]" type="text" class="txtText" id="stock[]" size="6" maxlength="5" value="-99"></td>
                    <td><input name="stash[]" type="text" class="txtText" id="stash[]" size="6" maxlength="5" value="0" ></td>
                    <td><select name="act[]" class="txtText" id="act[]">
                      <option value="1"  Selected >Active</option>
                      <option value="0" >Inactive</option>
                                                                    </select></td>
                  </tr>
    HTML:
    This is the sample code for one product. More than 100 listed on the page.
     
    greatlogix, May 20, 2014 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Okay - even with all the info, it shouldn't amass to more than 100-120 bytes pr item, and even if you multiply that by 100 (why are you sending all the info, and not just changed info (add a checkbox for each item, for instance, that the user needs to check if he changes anything (can also be checked automatically if the content changes, via javascript)) it shouldn't be close to any limit. $_POST doesn't really have a limit, it just receives the content regardless of how much data it is, unless it times out.
     
    PoPSiCLe, May 20, 2014 IP
    greatlogix likes this.
  5. sarahk

    sarahk iTamer Staff

    Messages:
    28,500
    Likes Received:
    4,460
    Best Answers:
    123
    Trophy Points:
    665
    #5
    My main concern with the code that you've posted is that it doesn't make a whole heap of sense.

    If you have 100 products the code should look something like this:
    
    <tr>
        <td> </td>
        <td>Product Name                    <input type="hidden" name="product[30844][id]" value="30844">
        </td>
        <td><input name="product[30844][lp]" type="text" class="txtText" id="lp30844" value="26.99" size="7"></td>
        <td><input name="product[30844][dp]" type="text" class="txtText" id="dp30844" value="17.99" size="7"></td>
        <td><input name="product[30844][wp]" type="text" class="txtText" id="wp30844" size="7" value="10.00"></td>
        <td><input name="product[30844][trm]" type="text" class="txtText" id="trm30844" size="7" value="7.85">                </td>
        <td><input name="product[30844][si]" type="text" class="txtText" id="si30844" value="28x52" size="9"></td>
        <td><input name="product[30844][pcode]" type="text" class="txtText" id="pcode30844" value="c-W836" size="7" maxlength="20"></td>
        <td><input name="product[30844][lbs]" type="text" class="txtText" id="lbs30844" value="0" size="7" maxlength="20"></td>
        <td><input name="product[30844][oz]" type="text" class="txtText" id="oz30844" value="9" size="7" maxlength="20"></td>
        <td><input name="product[30844][stock]" type="text" class="txtText" id="stock30844" size="6" maxlength="5" value="-99"></td>
        <td><input name="product[30844][stash]" type="text" class="txtText" id="stash30844" size="6" maxlength="5" value="0" ></td>
        <td><select name="product[30844][act]" class="txtText" id="act30844">
                <option value="1"  Selected >Active</option>
                <option value="0" >Inactive</option>
            </select></td>
    </tr>
    HTML:
    I'm not even sure that the id you have given the inputs would work and they're unlikely to be unique if the code is looping through
    id="wp[]"

    You can drop the hidden field too - I just left it in because you had it.
     
    sarahk, May 20, 2014 IP
  6. #6
    Are you running PHP 5.3.9 (or higher)? If so, check the php.ini value for max_input_vars.

    There's a similar setting for suhosin, if you're using that.

    
    [suhosin]
    suhosin.request.max_vars = XXX
    suhosin.post.max_vars = XXX
    
    Code (markup):
     
    nico_swd, May 21, 2014 IP
    greatlogix likes this.
  7. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #7
    Ah! Here you are. Super PHP expert! The one and only nicoSWD.

    max_input_vars was commented. I removed the comment and set it's value to 5000 and it worked. Thanks you saved my day.
     
    greatlogix, May 27, 2014 IP
    nico_swd likes this.
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    I'm glad to hear that!

    Just one thing I'd like to add. This php.ini setting was not introduced to mess with you, but to protect you. It prevents users from sending a lot of data to your site, which, under normal circumstances, all gets processed by PHP. This can be used to DDoS your server. So setting this value to 5000 seems a little high to me. Make a rough estimation on how many vars (including cookies, GET, POST) you're expecting in the worst case scenario, and set this value a little higher than that.
     
    nico_swd, May 27, 2014 IP
    greatlogix likes this.
  9. greatlogix

    greatlogix Active Member

    Messages:
    664
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #9
    Only one admin page which have so many form values to submit. Is it possible to set max_input_vars for one page only to avoid DDos thing?
     
    greatlogix, May 30, 2014 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375