How do I capture all input names of $ _POST ['my_image']?

I have dynamic inputs with names my_image[url] and my_image[caption]

<input name="my_image[url]" type="hidden" value="<?php echo $imgurl['url'];?>"/>
<input name="my_image[caption]" type="text" value="<?php echo $imgurl['caption'];?>">

Even inserting several images and captions dynamically, inside the isset the $ _POST [‘my_image’] is capturing only 1 image 1 caption:

if (isset($_POST['my_image'])){ 
    update_option('imagens_inicio',array($_POST['my_image']);
    echo '<pre>'; var_dump($_POST['my_image']);echo '</pre>';
}

array(1) {
  [0]=>
  array(2) {
    ["url"]=>
    string(96) "http://localhost/theme/wp-content/uploads/2017/08/4e07dd2bd752b989e9b4687129982977.jpg"
    ["caption"]=>
    string(0) "test text"
  }
}

How do I make the array be created in a continuous sequence:

url[]
caption[]
url[]
caption[]

With the current HTML code … not at all, since your naming does not support multiple values.

you need the input field names to support multiple values:

<input name="my_image[0][url]" type="hidden" value="...">
<input name="my_image[0][caption]" type="text" value="...">

To complete what @Dormilich posted, you can use for array push

<?php
var_dump($_POST);
?>

<form action="" method="post">
<input name="my_image[url][]" type="hidden" value="1"/>
<input name="my_image[url][]" type="hidden" value="2"/>
or
<input name="my_image[][url]" type="hidden" value="1"/>
<input name="my_image[][url]" type="hidden" value="2"/>
depending on how you need

<input type="submit" value="Send"/>
</form>

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.