Dropdown values in human readable for custom email template

pgrnycomdir 06 Feb, 2019
I have a form that is mailed to multiple groups. One group will require a custom template. I have done the custom template and it works as expected.

However, there is a drop down field which may contain multiple answers. The array is handled fine, but the info in the email template is the data that goes to the database and not the nice human readable.

By looking at the forum I have read that I need to write php (copied and changed the field names and values), but I have no idea where to put this code.

<?php
$regions_array = array(
Region_1 => 'Region 1',
Region_2 => 'Region 2',
Region_3 => 'Region 3',
Region_4 => 'Region 4',
Region_5 => 'Region 5',
Region_6 => 'Region 6',
Region_7 => 'Region 7',
Region_8 => 'Region 8',
Region_9 => 'Region 9',
);
$regions = array();
foreach ( $form->data['regions'] as $v ) {
$region[] = $region_array[$v];
}
$form->data['regions'] = implode(', ', $regions);
?>

I would like the custom email template to be the Region 1, Region 3, Region 5. Instead of the [Region_1, Region_3, Region_5] which is presently the return info in the custom email template.

Any help would be greatly appreciated.
Donna
healyhatman 06 Feb, 2019
Put it in a php block, without the tags.

Instead of $form->data['field'] you need to use $this->data("field")

Return the implode'd value and then use {var:php_name} in your email.
pgrnycomdir 07 Feb, 2019
healyhatman,

I appreciate your response but I don't understand this. I don't understand php either.

I found where I can add a php block, but where do I put that block, at the top right after display form? Above the custom template section?

So do I just put this in?


$this->data["regions"] = implode (', ', $regions);

Then in the Custom Template use the php block name of {var:reg_nm}

Thank you.
healyhatman 07 Feb, 2019
Round brackets buddy for $this->data

You put it in your submit event before your email action.
pgrnycomdir 07 Feb, 2019
OK, so I put in the following:

$this->data("regions") = implode ( ', ', $regions);


The php code went into a block just above the email and I changed the template to be {var:php13}

The block for php was php13 and it returns an error in line 1 and cannot process. I have no clue what the heck I'm doing.

Sorry, no joy.
healyhatman 08 Feb, 2019
$region_array = array(
"Region_1" => 'Region 1',
"Region_2" => 'Region 2',
"Region_3" => 'Region 3',
"Region_4" => 'Region 4',
"Region_5" => 'Region 5',
"Region_6" => 'Region 6',
"Region_7" => 'Region 7',
"Region_8" => 'Region 8',
"Region_9" => 'Region 9'
);

return implode(", ", array_intersect_key($region_array, array_flip($this->data("regions")));
pgrnycomdir 08 Feb, 2019
Well, getting closer.

Returned and error:

​0 syntax error, unexpected ';', expecting ',' or ')'

Not sure what this means, except that there is a line with punctuation that is incorrect??

Thank you.
Donna
healyhatman 08 Feb, 2019
Works for me, make sure you copied it properly.
pgrnycomdir 08 Feb, 2019
I copied and pasted. The only change is that it's a number to the Region. ie. "1"=Region 1

Here's what I pasted:

$region_array = array(
"1" => 'Region 1',
"2" => 'Region 2',
"3" => 'Region 3',
"4" => 'Region 4',
"5" => 'Region 5',
"6" => 'Region 6',
"7" => 'Region 7',
"8" => 'Region 8',
"9" => 'Region 9'
);

return implode(", ", array_intersect_key($region_array, array_flip($this->data("regions")));

I tried it again and am getting the same syntax error.
healyhatman 08 Feb, 2019
My bad. missing a bracket.
return implode(", ", array_intersect_key($region_array, array_flip($this->data("regions"))));
pgrnycomdir 08 Feb, 2019
Absolutely no worries!!!

I'll give this a try. And Thank You very much!!!

Donna
pgrnycomdir 08 Feb, 2019
Worked beautifully!!!

Many thanks to you healyhatman!!!
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger