We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21025
    • 6 Posts
    ...No one’s got anything? Not even a hint? Pleeeeeeeaaassseeee?? I’ll trade you.. CSS knowledge! It’s all I have! :’(
      • 14162
      • 67 Posts
      Read this post and found it very helpful in sorting out how to use a checkbox array in formit2db. If I have a series of checkboxes with the same name (e.g. name="favouritecar[]") and I want to send it to a custom table using formit2db, all I get is ’array’ in the table field.

      The following is my tweak to the formit2db snippet, derived from this thread:
      //replace lines 33 to the end with the following
      $allFormFields = $hook->getValues();    
      foreach ($allFormFields as $field=>$value){
          
      	if (is_array($value) && $field !== 'spam' && $field !== 'resource_id') {
      	$valuepieces = implode(',',$value);
      
      	$dataobject->set($field,$valuepieces);
      	}
      
          elseif ($field !== 'spam' && $field !== 'resource_id'){
              $dataobject->set($field,$value);
          }       
      }
      $dataobject->save();
      
      return true;


      This will add a comma delimited list to the custom table field, instead of ’array’. Then a simple matter of cycling through the field (using another snippet) if you want to check if a checkbox is already ticked.