Forums

Dynamic Check Box Group - Email 'Text Key' NOT 'Value'

ryanClaret 17 Jan, 2016
Hi,

I use a checkbox group, which is populated by using Dynamic Data loaded from a DB table.

For example:
{ID:180, Title: Bristol}
{ID: 182, Title London}.

My Checkboxes then Display as :

[] - Bristol (The checkbox value is the ID(180));
[] - London (The checkbox value is the ID(182));

When the form is completed, the values are stored in a DB cell correctly (180, 182).

However, in the email, I want to send the text value of "Bristol" or "London" rather than the ID?
Is this possible? How can I access the Checkbox 'Text Key' rather than the 'Value'?


The email should read: "Hi, A new user has registered, and has selected Bristol, London.".
But, it currently reads : "Hi, A new user has registered, and has selected 180, 182."


All help greatly appreciated!

Thanks
ryanClaret 18 Jan, 2016
Hi GreyHEad,a nd thanks for the quick reply!

Just a little more help if possible?

1) Does this code go in a "Custom Code" before or after the "HandleArrays" event?

2) I am loading "checkboxgroup[]" from the DB dynamically, so I cannot 'hard type' the values the array will hold like you have with the code below.


<?php
$color_array = array(
  1 => 'green',
  2 => 'blue',
  3 => 'red',
  4 => 'white'
);
$color_names = array();
foreach ( $form->data['colors'] as $v ) {
  $color_names[] = $color_array[$v];
}
$form->data['color_names'] = implode(', ', $color_names);
?>


I have adapted your code to the below, but this results in nothing being shown in the email?


<?php
$location_array = $form->data['checkboxgroup[]'];
$location_names = array();
foreach ( $form->data['checkboxgroup[]'] as $v ) {
  $location_names[] = $location_array[$v];
}
$form->data['location_names'] = implode(', ', $location_names);
?>


Email:


A new user has been created

1) {name}

2 ) {location_names}
GreyHead 18 Jan, 2016
Hi ryanClaret,

The code would go before any Handle Arrays action.

The example is for a single checkbox - it needs to be modified to deal with a checkbox group. As they are dynamic you'll probably need to add a database query to get to matching values back.

Bob
This topic is locked and no more replies can be posted.