jcadima
6/4/2015 - 2:16 PM

Loop checkboxes and store them comma separated in string

Loop checkboxes and store them comma separated in string

<?php

    // Loop the swagbags[] array of checkboxes  
    $checkboxes=$_POST['swagbags'];  
    $swagbags="";  
    foreach($checkboxes as $chk)  
       {  
          $swagbags .= $chk.",";  // append each selected checkbox value, comma separated
       } 
    
  
  
// THE HTML:    
<input type="checkbox" name="swagbags[]" value="Compfit">Compfit: Approximately 1,100 Athletes
<input type="checkbox" name="swagbags[]" value="Samson Games">Samson Games: Approximately 200 Athletes
<input type="checkbox" name="swagbags[]" value="5K">Crush 5K: Approximately 750 Athletes 					
<input type="checkbox" name="swagbags[]" value="Volunteers">Volunteers: Approximately 200 total