Re-ordering Form elements on email to match webview

Permalink
OK, we have a normal form that emails results to a group mailbox, but the ordering of each question in the email does not mirror the way the questions are ordered on the actual view.

Branch - akID[136]
Title - akID[137]
First Name - akID[64]
Surname - akID[65]
House name / number - akID[66]
Street - akID[67]
City / Town - akID[69]
County - akID[70]
Postcode - akID[72]
Primary telephone number - akID[74]
Secondary telephone number - akID[75]
Email Address - akID[73]
First Pets name - akID[76]
Date of Birth - akID[77]
Species - akID[113]
Breed - akID[79]
Colour - akID[80]
Sex - akID[81]
Neutered - akID[82]
Microchip number - akID[114]
Last vaccinated - akID[83]
Insured with - akID[84]
Previous Vets name - akID[85]
Telephone number - akID[86]
Address - akID[87]
How did you hear about us? - akID[88]
Marketing opt-in - akID[129]

I'm guessing this is because the web form orders in akID? The questions above are the correct order but of course they're all over the place on the email.

Apart from re-adding the form and adding the questions in the correct order, anyone got any suggestions on how I can re-order easier?

I've already tried the drag to re-order and that's done nothing.

# concrete5 Version
Core Version - 8.3.2
Version Installed - 8.3.2
Database Version - 20180122213656

zapbrannigan1972
 
mnakalay replied on at Permalink Reply 1 Attachment
mnakalay
The problem is the attributes are not ordered following your form organization but following their organizing in the object.

I had to deal with that not long ago and I came up with a solution that works for me. I am attaching the file. Just unzip it and put it in application\mail and it should work.

Here's the code for reference:
<?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 = '';
$attributesArray = [];
$formAttributesArray = [];
foreach ($attributes as $value) {
    $attributesArray[$value->getAttributeKey()->getAttributeKeyHandle()] = $value;
}
$form = $entity->getDefaultViewForm();
foreach ($form->getFieldSets() as $fieldSet) {
    foreach ($fieldSet->getControls() as $setControl) {
        $ak = $setControl->getAttributeKey();
        $value = $attributesArray[$ak->getAttributeKeyHandle()];