HTML Form Submit pass array to PHP [closed]

You can use hidden inputs:

<input type="hidden" name="image_ids[]" value="1">
<input type="hidden" name="image_ids[]" value="2">
<input type="hidden" name="image_ids[]" value="3">

Just create a new hidden input for each image id, with the same name image_ids[].

Note that when you append [] to the name of various input fields, these values are submitted as an array, in this case named image_ids.

Another solution is just to concatenate all the IDs with a comma: "1,2,3,4,5" and send it in just one hidden input field (instead of a bunch of hidden input fields), then in your server script (assuming you’re using PHP) you can convert the string "1,2,3,4,5" to an array using something like: $image_ids = explode(',', $_POST['image_ids']);.

Good look.

Leave a Comment