Getting data from dynamically allocated metaboxes within a custom post

Found a solution, although you have to change your premise a bit.

  1. Really can not add more than one metabox that uses a common draw and save callback.
  2. The names have to unique for the fields, just like in standard form processing.

So what I did it this 1 metabox, with my variation of repeatable fields.

function add_manual_form() 
 { 
  add_meta_box( 'List_Group1',
              __( 'List Records', 'myplugin_textdomain'  ),
                 'TEST_card',
                 'mmdlist',
                 'normal',
                 'high'
                  );            
  }
 add_action( 'add_meta_boxes', 'add_manual_form' );
 add_action( 'save_post', 'save_TESTCARD');

function TEST_card($post_ID, $Arg)
{
$RecordCnt = TotalRecordsInDatabase($post_ID);
$RecordCnt +=1;
for($i=1; $i<=$RecordCnt; $i ++) 
DrawRecordSet($i);

?>

<form id="ADD_LIST_RECORD" name="ADD_LIST_RECORD" method="post" action="">
 <input type="submit" name="ADD_LIST_RECORD" id="ADD_LIST_RECORD" value="ADD    RECORD" />
</form>


<?php
}


function DrawRecordSet($Index)
{
?>

 <select name="field1_<?php echo $Index; ?>">
 <option value="">Select something...</option>
 <option value="something">Something</option>
 <option value="else">Else</option>
 <option value="too">too</option>
 </select>

<select name="field2_<?php echo $Index; ?>">
  <option value="">Select something...</option>
  <option value="stuff">1</option>
  <option value="junk">Else</option>
  <option value="too">too</option>
</select>
<br /><br /><br />
<?php
// Add a responsive button to add more record sets
}


function save_TESTCARD($post_ID) 
  {
  for($i=1; $i<=3; $i ++)
    {
    if( array_key_exists( 'field1_'.$i, $_POST ) )
      {
      $InputValue = $_POST[ 'field1_'.$i ];
      DebugLog('Field1_'.$i.': '.$InputValue);
      }

   if( array_key_exists( 'field2_'.$i, $_POST ) )
     {   
     $InputValue = $_POST[ 'field2_'.$i];
     DebugLog('Field2_'.$i.': '.$InputValue);
     }
  }

}

To add a new record and save the present ones, I have added a old-style HTML submit button. This button passing nothing force the save & redraw routine. No data is passed.

This is just test code. It demonstrates the following:

  1. How to dynamically add same fields to a meta box
  2. How to ensure that these new fields have unique names
  3. How to retrieve the data from these fields

And there ya go for repeatable fields within a metabox, without all the other overhead. So unless someone can explain to me why this solution is problem..I am going for it. What I like is that it is small and tight code, using the database as a simulated variable. The only heavy use, is hitting the database, however since this is for the admin section of WordPress, it really does not matter.