Forums

get dropdown text in email

juansolos 13 Jun, 2017
Hi,
I am looking for get the text of a dropdown in the email. Text not value.
I have seem this.
<?php
$color_array = array(
  1 => 'green',
  2 => 'blue',
  3 => 'red',
  4 => 'white'
);
$form->data['color_name'] = $color_array[$form->data['color']];
?>

It works fine but my dropdown is dynamicly generated from a table of the database (contact detail ) as id=>name

I know that a dropdown with value = text will solve the problem but i need id as value, because i use it to get other data by ajax.

Any help
Regards
GreyHead 13 Jun, 2017
Hi juansolos,

There are two ways to do this:

One is to use a DB Read action or a Custom Code action to look up the matching database record and read the values that you need,

The other is to build the dynamic values using both the id and the text e.g. 1#green=green then you can use a custom code action in the On Submit event to separate the two parts into separate $form->data entries.

Bob
juansolos 13 Jun, 2017
Hi,
thanks.
I use a dropdown field (hidden) in the form.
And a db read and custom code on an event to dynamicly generate the hidden dropdown field depending from another one.

That seems to solve my problem
This topic is locked and no more replies can be posted.