0

I have a form which has a multiple option selector in it:

<td>
   <input type="checkbox" name="chk[]" checked="checked" />
</td>
<td>
   <select id="loyaltyType" required="required" name="VX_TYPE[]">
      <option>Choose Type</option>
      <option value="A">A</option>
      <option value="B">B</option>
      <option value="C">C</option>
      <option value="D">D</option>
   </select>
</td>
<td>
   <input type="text" required="required" class="small"  name="VX_NAME[]">
</td>
<td>
   <input type="text" required="required" class="small"  name="VX_EMAIL[]">
</td>
<td>
   <select name="VX_LOCATION[]" multiple>
      <option value="London">London</option>
      <option value="New York">New York</option>
      <option value="Paris">Paris</option>
      <option value="Tokyo">Tokyo</option>
   </select>
</td>

I would like the form to print with the following input/output:

Input:

B, sample name, sample email, New York + Toyko selected

D, sample name2, sample email2, London + Toyko selected

Output:

B, sample name, sample email, New York, Tokyo.

D, sample name2, sample email2, London, Tokyo.

However the actual output I am getting is as follows:

Actual output:

B, sample name, sample email, New York.

D, sample name2, sample email2, Tokyo.

This is the code for the output so far that does not work:

<?php foreach($VX_TYPE as $a => $b){ ?>
<p>
   <?php echo $VX_TYPE[$a]; ?>, <?php echo $VX_NAME[$a]; ?>, <?php echo $VX_EMAIL[$a]; ?>, <?php echo $VX_LOCATION[$a]; ?>
</p>
<?php } ?>

Any suggestions of how to get this working would be great!

user2798841
  • 291
  • 1
  • 4
  • 15

1 Answers1

0

assuming you get the following in your post:

 array (
       VX_NAME  =>(
               [1] = sample1
               [2] = sample2
       )
       VX_TYPE => (
               [1] = B
               [2] = D
       )
       VX_LOCATION => (
               [1] = London
               [2] = Tokyo
               [3] = New York
     )
  )

your VX_LOCATION and VX_TYPE selections are going to be put into one array with no association to the NAME,EMAIL. The form gives the user to add additional rows. you will need to associate them to the location/type.

for example:

     array (
       VX_NAME  =>(
               [1] = sample1
               [2] = sample2
       )
       VX_TYPE => (
               [1] = B
               [2] = D
       )
       VX_LOCATION[1] => (
               [1] = New York
               [2] = Tokyo
       )
       VX_LOCATION[2] (
               [1] = London
               [2] = Tokyo
       )
  )

then you can do:

 foreach ($_POST['VX_NAME'] as $k => $v){
  echo $_POST['VX_TYPE'][$k] . "," . $v. ",". $_POST['VX_EMAIL'].",";
    foreach ($_POST['VX_LOCATION'][$k] as $kk => $vv){
       echo $vv . ",";
    }
 echo "<br>";
 }
bart2puck
  • 2,432
  • 3
  • 27
  • 53