Is the INPUTS order in POST guaranteed to enter an array in PHP?

I have a form in which users enter an unlimited number of rows of data. They come to the form by entering any number of lines on the screen that they desire.

<?php $numRows = $_GET['NUM_ROWS_REQUESTED']; ?> <form method="post"> <?php for($i = 0; $i < $numRows ;$i++) { $uuid = uniqid(); ?> <input type="text" name="MYDATA[<?php print $uuid; ?>][FIRST_NAME]" /> <input type="text" name="MYDATA[<?php print $uuid; ?>][LAST_NAME]" /> <?php } ?> </form> 

I am wondering if, after publishing the form, I get these entries in the $_POST['MYDATA'] , if I can be guaranteed that they will be ordered in the same sequence as on the screen. Or will they be ordered using uniqid() , which is randomly generated?

The reason why I use a unique identifier instead of integers, which will be easier to arrange, is because users can delete lines and add extra lines using javascript on this page. It would be too difficult to check for collisions.

+17
html php html-form
Dec 09 '10 at 16:37
source share
2 answers

The W3 specification does not contain rules in which order form values ​​should be collected into a data set, so technically you cannot be sure. On the other hand, I have not seen a case (from numerous browsers in numerous operating systems over the years) where data was not sent in a list-listing-order. I really did not check cases where I changed the tabindex default values ​​(UI).

You can always sort the array ( asort ) after you get it, to be sure which order you are reading.

+8
Dec 09 2018-10-09
source share

This is guaranteed by HTML4.01 (for -urlencoded, but it is assumed to be identical for / form -data), and all current browsers present form fields in the order in which they appear in the document.

So yes, they are ordered by their appearance and not by random uuid.

+5
Dec 09 2018-10-09
source share



All Articles