ShadowMage Posted September 15, 2011 Share Posted September 15, 2011 I have a bunch of inputs set up to submit in an array, ie: <input type='text' name='length[]' value='' /> These inputs are submitted to a PHP script which loops through each of them and constructs a semi-colon delimited string, ie: for ($x=0; $x<5; $x++) { if ($x > 0) { $tmpLengthString.=';'; } if (isset($_POST['length'][$x])) { $tmpLengthString.=str_replace(',', '', $_POST['length'][$x]); }} It is supposed to produce a string that, when exploded on the semi-colon, will create an array of 5 elements.Works great when the inputs are all filled in from left to right up to a certain point. Ie, length[0], length[1], length[2] are filled in but length[3] and length[4] are not. (produces '0;1;2;;')The problem appears when the first one (or more) are not filled in. Ie, length[0] and length[1] are blank, but length[2-4] are filled in. (produces '2;3;4;;' when it should produce ';;2;3;4')It also happens if one is skipped. Ie, 0-2 filled, 3 blank, 4 filled. (produces '0;1;2;4;' when it should produce '0;1;2;;4') The issue is that the blank inputs don't submit to PHP. When 0-2 are filled they are populated in their respective places in $_POST['length'][0-2] but if, for example, 0-2 are left blank, then 3 will be put in $_POST['length'][0].Does that make sense? Is there a way to force those blank inputs to submit? Link to comment Share on other sites More sharing options...
Ingolme Posted September 15, 2011 Share Posted September 15, 2011 Put a number between the square brackets: <input type='text' name='length[0]' value='' /> <input type='text' name='length[1]' value='' /><input type='text' name='length[2]' value='' /> Link to comment Share on other sites More sharing options...
ShadowMage Posted September 15, 2011 Author Share Posted September 15, 2011 Wow! Who'da thunk it could be so simple! Thanks, Ingolme! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.