EricWebsite
Member
I have a form where on submission I compare the original data with the current (possibly updated) data.
I mark the updates with a color and mail them to an administrator.
That works well for normal fields. But for checkboxes the output in the original data colum looks like: ["1","2","10","11","5","7","8"] while in the current content it is shown as a nice bullet list of the Labels.
How can I extract the labels from the $origData as well? My code:
Any ideas? Thanks in advance!
I mark the updates with a color and mail them to an administrator.
That works well for normal fields. But for checkboxes the output in the original data colum looks like: ["1","2","10","11","5","7","8"] while in the current content it is shown as a nice bullet list of the Labels.
How can I extract the labels from the $origData as well? My code:
PHP:
<?php
$origData = $formModel->getOrigData();
$fieldtobecompared = array ('tablename___initials', 'tablename___firstname', 'tablename___lastname', 'tablename___username', 'tablename___email', 'tablename___street', 'tablename___number', 'tablename___postalcode', 'tablename___city', 'tablename___volunteertasks');
// volunteertasks is the checkbox element
echo '<table><tr><td>Field</td><td>Previous value</td><td>New value</td></tr>';
foreach ($fieldtobecompared as $field) {
$original = $origData[0]->$field;
$current = $this->data[$field];
if ($original != $current) {
$color = 'red';
} else {
$color = 'black';
}
echo '<tr><td style = "color: ' . $color . ';">' . str_replace ('tablename___', '', $field) . '</td>';
echo '<td>' . $original . '</td><td>' . $current . '</td></tr>';
}
echo '</table>';
?>