Forums

checkboxgroup data to db and mail

chuanse 01 May, 2012
Hello,

I have a form where users have to indicate which rooms they want to reserve for an event.
For that I have setup a checkbox group. The data is not saved into the db, the field stays NULL for some reason.
In the mail sent after submission I got this line:[ array ( 0 => 'auditorium_1_200', 1 => 'skillslab_ABC',)] but I would like to see the labelnames instead...
I found info about what i want to do on the forum but it isn't useful to me since the phpcode provided in those posts is rather for identical values with an incremental suffix (a_value_1,a_value_2,...)

How can i fix this issue?

Thx.

these are the values in the checkbox group
auditorium_1_200=Auditorium 1 voor 200 personen
auditorium_2_200=Auditorium 2 voor 200 personen
auditorium_1_100=Auditorium 1 voor 100 personen
auditorium_2_100=Auditorium 2 voor 100 personen
auditorium_3_100=Auditorium 3 voor 100 personen
auditorium_4_100=Auditorium 4 voor 100 personen
seminarie_1=Seminariezaal 1 voor 50 personen
seminarie_2=Seminariezaal 2 voor 50 personen
seminarie_3=Seminariezaal 3 voor 50 personen
seminarie_4=Seminariezaal 4 voor 50 personen
pcleslokaal_1=Computerleslokaal 1 voor 20 personen
pcleslokaal_2=Computerleslokaal 2 voor 20 personen
skillslab_ABC=Skillslab deel ABC Geneeskunde
skillslab_D=Skillslab deel D Kinesitherapie


this is the sourcecode
<div class="ccms_form_element cfdiv_checkboxgroup label_over radios_over" id="lokalen_container_div"><input type="hidden" name="lokalen" value="" alt="ghost" />
<div style="float:left; clear:none;"><input type="checkbox" name="lokalen[]" id="lokalen_0" title="" value="auditorium_1_200" class="validate['group[30]']" />
<label for="lokalen_0">Auditorium 1 voor 200 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_1" title="" value="auditorium_2_200" class="validate['group[30]']" />
<label for="lokalen_1">Auditorium 2 voor 200 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_2" title="" value="auditorium_1_100" class="validate['group[30]']" />
<label for="lokalen_2">Auditorium 1 voor 100 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_3" title="" value="auditorium_2_100" class="validate['group[30]']" />
<label for="lokalen_3">Auditorium 2 voor 100 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_4" title="" value="auditorium_3_100" class="validate['group[30]']" />
<label for="lokalen_4">Auditorium 3 voor 100 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_5" title="" value="auditorium_4_100" class="validate['group[30]']" />
<label for="lokalen_5">Auditorium 4 voor 100 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_6" title="" value="seminarie_1" class="validate['group[30]']" />
<label for="lokalen_6">Seminariezaal 1 voor 50 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_7" title="" value="seminarie_2" class="validate['group[30]']" />
<label for="lokalen_7">Seminariezaal 2 voor 50 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_8" title="" value="seminarie_3" class="validate['group[30]']" />
<label for="lokalen_8">Seminariezaal 3 voor 50 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_9" title="" value="seminarie_4" class="validate['group[30]']" />
<label for="lokalen_9">Seminariezaal 4 voor 50 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_10" title="" value="pcleslokaal_1" class="validate['group[30]']" />
<label for="lokalen_10">Computerleslokaal 1 voor 20 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_11" title="" value="pcleslokaal_2" class="validate['group[30]']" />
<label for="lokalen_11">Computerleslokaal 2 voor 20 personen</label>
<input type="checkbox" name="lokalen[]" id="lokalen_12" title="" value="skillslab_ABC" class="validate['group[30]']" />
<label for="lokalen_12">Skillslab deel ABC Geneeskunde</label>
<input type="checkbox" name="lokalen[]" id="lokalen_13" title="" value="skillslab_D" class="validate['group[30]']" />
<label for="lokalen_13">Skillslab deel D Kinesitherapie</label>
</div><div class="clear"></div><div id="error-message-lokalen"></div></div>
GreyHead 02 May, 2012
Hi chauase,

The form will return an array of value of the selected options, not their labels. That's just how HTML forms work.

To convert the array to a string please drag a Handle Arrays action into the OnSubmit event and move it up before the Email action.

If you want to convert the values back into more meaningful text then you need to add a Custom Code action to do that, probably before the Handle Arrays action.
<?php
$localen_array = array(
  'auditorium_1_200' => 'Auditorium 1 voor 200 personen',
  'auditorium_2_200' => 'Auditorium 2 voor 200 personen',
  'auditorium_1_100' => 'Auditorium 1 voor 100 personen',
  'auditorium_2_100' => 'Auditorium 2 voor 100 personen',
  'auditorium_3_100' => 'Auditorium 3 voor 100 personen',
  'auditorium_4_100' => 'Auditorium 4 voor 100 personen',
  'seminarie_1' => 'Seminariezaal 1 voor 50 personen',
  'seminarie_2' => 'Seminariezaal 2 voor 50 personen',
  'seminarie_3' => 'Seminariezaal 3 voor 50 personen',
  'seminarie_4' => 'Seminariezaal 4 voor 50 personen',
  'pcleslokaal_1' => 'Computerleslokaal 1 voor 20 personen',
  'pcleslokaal_2' => 'Computerleslokaal 2 voor 20 personen',
  'skillslab_ABC' => 'Skillslab deel ABC Geneeskunde',
  'skillslab_D' => 'Skillslab deel D Kinesitherapie'
);
$lokalen_names = array();
foreach ( $form->data['lokalen'] as $v ) {
  $lokalen_names[] = $localen_array[$v];
}
$form->data['lokalen_names'] = implode(', ', $lokalen_names);
?>
This will give you a comma separated list of labels that you can use in the template by adding {lokalen_names}

Bob
chuanse 03 May, 2012
Thanks a lot Greyhead ;-)
This topic is locked and no more replies can be posted.