Page 1 of 1

CGBetterForms Arrays not appearing

Posted: Mon Feb 08, 2021 7:55 pm
by blackrain
I have been trying to use the CGBetterForms module with checkboxes.

Code: Select all

<input id="1b-1" type="checkbox" class="" name="purpose[]" value="New business"/><span>New business</span>
<input id="1b-2" type="checkbox" class="" name="purpose[]" value="Renewals"/><span>Renewals</span>
<input id="1b-3" type="checkbox" class="" name="purpose[]" value="Claims"/><span>Claims</span>
<input id="1b-4" type="checkbox" class="" name="purpose[]" value="Accounts"/><span>Accounts</span>
<input id="1b-5" type="checkbox" class="" name="purpose[]" value="Compliance"/><span>Compliance</span>
<input id="1b-6" type="checkbox" class="" name="purpose[]" value="Administration"/><span>Administration</span>
however the results do not look right, in some cases I managed to get Array as a result and when using a Foreach loop I just got the first letter i.e.
N
R
C
A
C
A

Code: Select all

{foreach from=$_purpose item=item}{$item.value}<br />{/foreach}
I am sure there is a solution but the user guide doesn't show anything about results delivery via email and .csv file creation.

Any help would be greatly appreciated

Mark

Re: CGBetterForms Arrays not appearing

Posted: Tue Feb 09, 2021 5:46 pm
by blackrain
OK this is now fixed, after some experimenting I used implode to display the array of checked inputs.
For the email results

Code: Select all

{if !empty($purpose)}<p><strong>1b. For what purpose do you use it?:</strong> {implode('<br />',$purpose)}</p>{/if}
For the flat file csv

Code: Select all

"{if !empty($purpose)}{implode('+',$purpose)}{/if}"
There isn't any documentation for results rendering and checkbox groups, hope this helps someone.

Mark