I have a form that I want to pass to PHP as an array. Simple enough, but I'd like the array to be:

Array ( [0] => Array ( 'name' => a 'email' => b ) [1] => Array ( 'name' => c 'email' => d ) [2] => etc ...)

Currently my form is:

<form action="" method="post" name="record[]">
<input type="text" name="record[0][name]"><input type="text" name="record[0][email]"><br>
<input type="text" name="record[1][name]"><input type="text" name="record[1][email]"><br>
<input type="button" class="button" value="submit">
</form>

but that passes 'name' and 'email' as [name],[email] which doesn't display the results that I'm looking for when I do a foreach().

Ultimately, I want to cycle through each record using PHP and echo:

name: a
email: b

name: c
email: d

Suggestions?

Thanks in advance.

    With a couple small changes (including changing the submit input element to type="submit"), this worked as expected for me:

    <html><head><title>test</title></head><body>
    <form action="" method="post">
        <input type="text" name="record[0][name]"><input type="text" name="record[0][email]"><br>
        <input type="text" name="record[1][name]"><input type="text" name="record[1][email]"><br>
        <input type="submit" class="button" value="submit">
    </form>
    <?php
    if(!empty($_POST)) {
        echo '<pre>'.print_r($_POST,1).'</pre>';
    }
    ?>
    </body>
    </html>
    

    Output:

    Array
    (
        [record] => Array
            (
                [0] => Array
                    (
                        [name] => name 1
                        [email] => email 1
                    )
    
            [1] => Array
                (
                    [name] => name 2
                    [email] => email 2
                )
    
        )
    
    )
    
      Write a Reply...