I'm working on a WordPress process, but this seems more like a general PHP and array manipulation question with specific relevance to WordPress, in this case relating to WooCommerce.
If I have a form that may submit anywhere from 1 to around 35 entries of the same type, then to my understanding I can create it as follows. I'm using first and last names.
The form inputs, simplified, look like this:
echo ' <input type="text" name="first_name[]" id="first_name" />';
echo ' <input type="text" name="last_name[]" id="last_name" />';
In the full version of the above, lines are replicated as many time as necessary, with an iterated variable distinguishing ids sequentially from each other, and with other values pre-filled and hidden. There's a parallel version meant to post variables as hidden fields.
The post action looks like this:
if (isset($_POST) == true) {
$att_data = array(
'last_name' => $_POST['last_name'],
'first_name' => $_POST['first_name']
);
The WordPress function add_post_meta then ought to add $att_data to the database. It works fine as a direct "add" action without a form, or with a dummy variable in place of the $_POST[...]. Unfortunately, however, what using versions of the form/submit/$_POST gives me on my debug console is
["last_name"]=> NULL ["first_name"]=> NULL
So, the form is submitting or at least the post action is posting and the the array is being sent, but the $_POST variables are not being captured. Why not?
ADDITIONAL: Wait a second - I'm wondering if WooCommerce clears all $_POST variables before re-directing... Am researching now.