Express Form: How to add Display Text to notification email?

Permalink
The "Display Text" field is not included in the notification email. Is there a way to add it by modifying the "/application/mail/block_express_form_submission.php" file?

BlueFractals
 
mnakalay replied on at Permalink Reply
mnakalay
Hello,
Add this to the mail template and it should do the trick
$controls = $entity->getDefaultViewForm()->getControls();
foreach ($controls as $control) {
    if ($control instanceof \Concrete\Core\Entity\Express\Control\TextControl) {
        $submittedData .= $control->getHeadline() . ":\r\n";
        $submittedData .= $control->getBody() . "\r\n\r\n";
    }
}
BlueFractals replied on at Permalink Reply
BlueFractals
That works to some extent but that only adds the "Display Text" fields without the other normal fields. It looks like `$controls = $entity->getDefaultViewForm()->getControls();` only retrieves the Display Texts. I am wanting to include all the fields as it appears on the form like shown below:

Section A
Personal Details
Name: John Doe
DOB: 12/12/1955
Gender: Male
Section B
Contact Details
Contact Number: 112233
Address: 123 Test Street
Email: jd@testtest.com

Is this possible?
mnakalay replied on at Permalink Reply
mnakalay
Yes, the idea was to add that code to what was already there not to replace it.

So the whole code is this:
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$formDisplayUrl = URL::to('/dashboard/reports/forms', 'view', $entity->getEntityResultsNodeId());
$subject = t('Website Form Submission – %s', $formName);
$submittedData = '';
$controls = $entity->getDefaultViewForm()->getControls();
foreach ($controls as $control) {
    if ($control instanceof \Concrete\Core\Entity\Express\Control\TextControl) {
        $submittedData .= $control->getHeadline() . ":\r\n";
        $submittedData .= $control->getBody() . "\r\n\r\n";
    }
}
foreach ($attributes as $value) {
    if ("image_file" != $value->getAttributeTypeObject()->getAttributeTypeHandle() || ($dataSaveEnabled && "image_file" == $value->getAttributeTypeObject()->getAttributeTypeHandle())) {
        $submittedData .= $value->getAttributeKey()->getAttributeKeyDisplayName('text') . ":\r\n";
BlueFractals replied on at Permalink Reply
BlueFractals
Yes that's exactly what I did and this is how the information was displayed:

Section A
Personal Details
Section B
Contact Details
Name: John Doe
DOB: 12/12/1955
Gender: Male
Contact Number: 112233
Address: 123 Test Street
Email: jd@testtest.com


It first displayed all the Display Texts, then displayed rest of the fields. I think we only need a single "foreach" loop but not sure how to get $controls and $attributes within the same foreach.
mnakalay replied on at Permalink Reply
mnakalay
Oh you mean you want all fields, including the text ones, in the exact same order they appear on the form?

That's going to need a little thinking. I'll send you something tomorrow
mnakalay replied on at Permalink Best Answer Reply
mnakalay
Try this
<?php
defined('C5_EXECUTE') or die("Access Denied.");
$formDisplayUrl = URL::to('/dashboard/reports/forms', 'view', $entity->getEntityResultsNodeId());
$subject = t('Website Form Submission – %s', $formName);
$submittedData = '';
$controls = $entity->getDefaultViewForm()->getControls();
foreach ($controls as $index => $control) {
    if ($control instanceof \Concrete\Core\Entity\Express\Control\TextControl) {
        // since the 2 arrays $controls and $attributes are in the same order
        // And the only difference is $controls contains the TextControl ones while $attributes doesn't
        // we can simply get those from $controls and insert them in $attributes at the right position
        array_splice($attributes, $index, 0, [$control]);
    }
}
foreach ($attributes as $value) {
BlueFractals replied on at Permalink Reply
BlueFractals
That's awesome. It worked as expected. Thanks!