drop down menu return values

How to display dropdown text instead of index values in CF emails.

Overview

The problem occurs because dropdown menus send index numbers instead of their corresponding text labels.
Create a custom PHP array mapping index numbers to text labels, then use an OnSubmit custom code to convert the index before sending the email.

Answered
jd jdran 28 Sep, 2015
I ve set some a dropdown menu to a contact form to induce user select a service he is interested to. However on email sent, only the according number of service is shown:
0=Service 1
1=Service 2
2=Service 3

and in email template it is:
<tr><td>Service interested to</td><td>{service}</td></tr>
but result is:
Service interested to 2
instead of:
Service interested to Service 3


Also, how can I set a zero (null) selection? Users sometimes do not select a service but just leave the first option on.
It is going to be required in validation and I want users to actually select a service.
Gr GreyHead 28 Sep, 2015
1 Likes
Hi jdran,

To set a null selection use the 'Empty option' box in the element.

For the useful info please see this FAQ

Bob
jd jdran 30 Sep, 2015
Answer
Done! I did it. Thank you.
Here is what I did for a simple required drop down in case anybody else needs a bit more of help:

1)
Created all necessary data in ecxel. The cells are in the following format:
1 = > ' Selection 1 ' ,
2 = > ' Selection 2 ' ,
etc.
Each data is in its own cell because excel uses ' =>' for other purposes than simple data. So I had to put everything in a single cell in a row. Then I used the function =CONCATENATE(A3;B3;C3;D3;E3;F3;G3) to create each row of my array:
1=>'Selection 1',
2=>'Se;ection 2',
etc

2)
Then I copied pasted the column with concateneted data to have an array to use to the code like:

<?php
$myCustom_array = array(
1=> 'Selection 1',
2=> 'Selection 2',
etc
);
$form->data['myCustomData_name'] = $myCustom_array[$form->data['DropDownformName']];
?>


and I put the above as a custom code in Setup (Chronoforms v5) into 'OnSubmit' before email action.

3)
In email action template I used the {MyCustomData_name} to send the result!

Good luck!
This topic is locked and no more replies can be posted.