ACF Form – How to add_post_meta with Multi-Array?

I have a question, hope it’s not too much to ask for a beginner. It’s basically a drop-down box letting you choose a car and submit your name to a list. I will add the remove functionality later, along with code sanitization.

What it is: It’s a drop-down <select> form that lets you choose an <option>. I’m trying to get the form to submit the chosen <option> and the logged-in user’s name to an array like so:

Read More
entries =>
     0 =>
string 'Mercedes SLS AMG GT3' (length=20) <- the <option> chosen
string 'John Doe' (length=20) <- the user's name
     1 =>
string 'Audi GT3' (length=20) <- the <option> chosen
string 'Peter Smith' (length=20) <- the user's name

etc…

I have an Advanced Custom Field setup (referenced from another node type), as the <select><option> list.

Pastebin if you don’t want to read below: http://pastebin.com/Hd1kiHxm

!! Thank you so ever much to anyone that wishes to help a noob on a hobby project !!

CODE BELOW:

<!-- Series Cars Stuff -->
<?php

$posts = get_field('series_cars_reference');
if( $posts ): ?>
    <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>
            <form name="choose_car" method="POST" action="">   
            <?php
            $rows = get_field('cars');
            if($rows) {
                echo '<select name="cars">';
                foreach($rows as $row)
                {
                    echo '<option name="cars" value="' . $row['car'] . '">' . $row['car'] . '</option>';
                }
            echo '</select>';
            echo '<input type="submit" name="submit" value="Submit"/>';
            }
        $current_user = $current_user->display_name;            
        $selectOption = Array(
          'entry' => array(
            'name' => $current_user,
            'car' => $_POST['cars'],
        ));
echo '<pre>'; print_r($selectOption);echo '</pre>';
            if(isset($_POST['submit'])){
                add_post_meta( get_the_ID(), 'entries', $selectOption );
            }
            ?>
            </form>

<!-- SHOW ALL POST DATA - VAR DUMP PRINT -->   
<h3>All Post Meta</h3>
<?php $getPostCustom=get_post_custom(); // Get all the data ?>
<?php
    foreach($getPostCustom as $name=>$value) {
        echo "<strong>".$name."</strong>"."  =>  ";
        foreach($value as $nameAr=>$valueAr) {
                echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                echo $nameAr."  =>  ";
                echo var_dump($valueAr);
        }
        echo "<br /><br />";
    }
?>

// BELOW IS WHAT THE OUTPUT PRINT VAR STUFF LOOKS LIKE:

entries =>
     0 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
     1 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
     2 =>
string 'a:2:{s:4:"name";s:5:"admin";s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=67)
     3 =>
string 'a:2:{s:4:"name";N;s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=57)
     4 =>
string 'a:2:{s:4:"name";N;s:3:"car";s:20:"Mercedes SLS AMG GT3";}' (length=57)
     5 =>

Related posts