0

I have a form which field can have multiple instances. Like for example the contact field. The user can add one or more contacts.

Now, when the form is submitted, I want it to send the data like this:

contact[0][type]
contacts[0][value]     --- first instance

contacts[1][type]
contacts[1][value]     --- second instance

contacts[2][type]
contacts[2][value]     --- third instance

and so on..

So that in my code, I can loop them like this:

$contacts = $_POST['contacts'];
foreach($contacts as $contact){
    echo $contact['type'] . '<br>';
    echo $contact['value'] . '<br>';
    echo '--------------------------';
}


Is it even possible? Or can you suggest a better way to do this?


  • 1
    Does this answer your question? [Submitting a multidimensional array via POST with php](https://stackoverflow.com/questions/2433727/submitting-a-multidimensional-array-via-post-with-php) – catcon Dec 18 '19 at 00:26
  • the answer on that link is the same as what I wanted, but it didn't say how to do the parameter name like that. – Lou KnowsAlready Dec 18 '19 at 10:13

0 Answers0