Showing "Label" instead of "value" in a Thanks-"Message section"

burf 28 Feb, 2019
Hi, when submitting a questionnaire users will see a Thanks Message and also receive an E-Mail, both a copy of the submitted information. There are questions which can be answered with „very good“, „good“ etc. In the database every such „Label“ is saved as a certain „value“ 1 to 6.

My problem is that in the Email section I can select „Auto add fields data“ which will send the „Labels“ of e.g. the radios group, which is fine, since I want the users to read their answer as „good“, and not, e.g., as „2“.

How can I add these labels into the „Message“ section? If I take as message the html-code from the „Template“ – in the form {data:fieldname} – only the "values" will be listed. But I would like to have the „Labels“ instead.

Best
Carsten

PS: In the options part of e.g. a radios group it says: „Multi line list of value=Label pairs, the values will be sent.“ In my case the Email section with „Auto add fields data“ activated, adds the „Label“, not the value.
healyhatman 28 Feb, 2019
You'll have to use PHP, or a Switch action. For example in a PHP block
$questionsMessage = "";
function getLabel($value) {
switch($value) {
case 1:
return "Bad";
break;
case 2:
etc etc
}
}

$message.= "Question 1: " . getLabel($this->data("question_1_field_name")) . "<br>";
$emssage.= "Question 2: " . getLabel($this->data("question_2_field_name")) . "<br>";
etcetcetc

return $message;
Then you can use {var:php_block_name} in your email body where you want the text to show.
You can also put all of your message text, HTML, and PHP in a "Custom Code" block set to return as var. Anything you "echo" or return (as in everything that would normally print to the screen) is instead sent to {var:custom_code_block_name} which you can then use in your email body.
burf 01 Mar, 2019
I used this code for two questions, but the resulting text only is "IST 1: "

-----
$questionsMessage = "";
function getLabel($value) {
switch($value) {
case 1:
return "Bad";
break;
case 2:
return "Bad";
break;
}
}

$message.= "IST 1: " . getLabel($this->data("radio25_ist01")) . "<br>";
$emssage.= "IST 2: " . getLabel($this->data("radio25_ist02")) . "<br>";

return $message;
-----
healyhatman 01 Mar, 2019
Your fieldname is actually called radio25_ist01? Can you put a debug in?
burf 01 Mar, 2019
Array
(
[option] => com_chronoforms6
[cont] => manager
[chronoform] => impuls_zdh
[event] => submit
[button131] =>
[textfield133_01_email] =>
[344c006c08b54da9e471dcdd364e4791] => 131974cd92bc0fdfc4b24618c50871b6
[4e7bff59a49d771d30d8dae637b24513] => 95a7c28875f22bc7b6800b8806d12699
[button6] =>
[button7] =>
[radio25_ist01] => 0
[radio26_ist02] => 3
)
Array
(
[save_data18] => Array
(
[data] => Array
(
[created] => 2019-03-01 08:26:37
[user_id] => 996
[radio25_ist01] => 0
[radio26_ist02] => 3
)

[_success] => Data saved successfully
[log] => Array
(
[0] => INSERT INTO `tbm2_chronoforms_data_impuls_zdh` (`created`, `user_id`, `radio25_ist01`, `radio26_ist02`) values ('2019-03-01 08:26:37', '996', '0', '3');
)

[var] => Array
(
[created] => 2019-03-01 08:26:37
[user_id] => 996
[radio25_ist01] => 0
[radio26_ist02] => 3
)

)

[php25] => Array
(
[returned] => IST 1: <br>
[var] => IST 1: <br>
)

[email19] => Array
(
[recipients] => Array
(
)
healyhatman 01 Mar, 2019
Yeah so obviously the code that looks for a 1 or a 2 isn't going to work if your values are 0 and 3 mate.
burf 01 Mar, 2019
got it :-)
burf 01 Mar, 2019
I am no PHP expert …

Now the answer to "IST 1" is listed ("IST 1: sehr wenig") – but not the answer to "IST 2" (radio26_ist02).

The PHP "switch" does not apply to all rows listed in the code as "$message.="?

How can I add the complete list of Questions/Answers to the resulting message? Do I need a PHP section for every single answer?
healyhatman 01 Mar, 2019
make your whole email message in a custom code block set to return as var. Example:
<p>This is a paragraph<\p>
<p>IST1:
<?php
switch($this->data("ist_01_fieldname_whatever")) {
case 1:
echo "hello guvna";
break;
......
} ?>
<\p>

<p>IST02:
<?php
switch($this->data("yougetthepicture")) {
...
..
{
?>
<\p>
burf 01 Mar, 2019
Does not work. When I only use the first part of the below code, the message is e.g. "IST1: etwas<\p>" (Which is apart from the <\p> correct.

But when I add a second section for the second question into the code, there comes an error message (T_STRING).Showing Showing <p>This is a paragraph<\p>
<p>IST1:
<?php
switch($this->data("radio25_ist01")) {
case 0:
echo "sehr wenig";
break;
case 1:
echo "ziemlich wenig";
break;
case 2:
echo "etwas";
break;
case 3:
echo "ziemlich viel";
break;
case 4:
echo "sehr viel";
break;
} ?>
<\p>

<p>This is a paragraph<\p>
<p>IST2:
<?php
switch($this->data("radio25_ist02“)) {
case 0:
echo "sehr wenig";
break;
case 1:
echo "ziemlich wenig";
break;
case 2:
echo "etwas";
break;
case 3:
echo "ziemlich viel";
break;
case 4:
echo "sehr viel";
break;
} ?>
<\p>
healyhatman 01 Mar, 2019
Answer
You put the wrong quotation marks in
switch($this->data("radio25_ist02“))
At the end of that line. I don't even know how you managed that
burf 01 Mar, 2019
Works. Thanks a lot.
This topic is locked and no more replies can be posted.