Hello, I’m looking for some guidance regarding formatting of Date/Time output when emailing a submitted Express form.
Right now, out of the box, when I include a date/time field in an express field and then email the form response, the output is like:
2023-10-26T14:30:00-07:00
This isn’t very readable. Any ideas?
General idea is to copy:
/concrete/mail/block_express_form_submission.php
to:
/application/mail/block_express_form_submission.php
and then replace this line (you will find it inside foreach loop):
$submittedData .= $value->getPlainTextValue() . "\r\n\r\n";
with something like:
if ($value->getAttributeTypeObject()->getAttributeTypeHandle() === 'date_time') {
$submittedData .= $value->getDisplayValue() . "\r\n\r\n";
} else {
$submittedData .= $value->getPlainTextValue() . "\r\n\r\n";
}
or
// Custom format of date fields
if ($value->getAttributeTypeObject()->getAttributeTypeHandle() === 'date_time') {
$dateDisplayMode = null;
$ak = $value->getAttributeKey();
if (is_object($ak)) {
$type = $ak->getAttributeKeySettings();
if (is_object($type)) {
$dateDisplayMode = (string)$type->getMode();
}
}
if ($dateDisplayMode === 'date') {
$submittedData .= app('helper/date')->formatCustom('d.m.Y', strtotime($value->getPlainTextValue())) . "\r\n\r\n";
} elseif ($dateDisplayMode === 'date_time') {
$submittedData .= app('helper/date')->formatCustom('d.m.Y H:i:s', strtotime($value->getPlainTextValue())) . "\r\n\r\n";
} else {
$submittedData .= $value->getPlainTextValue() . "\r\n\r\n";
}
} else {
$submittedData .= $value->getPlainTextValue() . "\r\n\r\n";
}
First code will use date format from current multilingual section.
Second one is always fixed format (check php date() documentation how to display it in your preferred format.)
Amazing Slawek, worked perfectly first try! Thank you for sharing your amazing skills.
If you’re feeling even more generous, I have another related wrinkle. On the public form, I would like the date/time picker to restrict days/times that people can choose. The cute little woman-run dog grooming shop is only open “Tuesday to Friday - 9:00am to 5:30pm”.