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.