Here’s a little snippet (hook) I wrote to process the arrays. I am using FormIt 1.5.5 and MODx Revolution 2.1 RC3:
The fiProcessArrays snippet:
<?php
/*
* fiProcessArrays formit hook. Processes all values stored as arrays and implodes them.
* Copyright Oleg Pryadko (websitezen.com) 2011
* License GPL 2 or later
*/
$fieldSuffix = $modx->getOption('fipaFieldSuffix',$scriptProperties,'_values');
$separator = $modx->getOption('fipaValueSeparator',$scriptProperties,', ');
$allFormFields = $hook->getValues();
foreach ($allFormFields as $fieldName => $fieldValue) {
if (is_array($fieldValue)) {
$imploded = '';
$count=0;
foreach ($fieldValue as $value) {
if (!empty($value)) {
if ($count) {$imploded .= $separator;}
$imploded .= $value;
$count++;
}
}
$hook->setValue($fieldName.$fieldSuffix,$imploded);
}
}
return true;
The FormIt call:
[[!FormIt?
&hooks=`fiProcessArrays,email`
&emailTpl=`ContactFormReport`
&emailTo=`[[++emailsender]]`
`]]
For each array field (e.g. checkbox field as described above), this snippet sets a new field value made from the field name and a suffix.
For example, for a favoriteColors[] array, the field value favoriteColors_values and corresponding email placeholder [[+favoriteColors_values]] will be created.