Adding checkboxes with custom code

nlheath 24 Feb, 2015
I have a form that loads a table from a database query using custom code. The only element on the form in design mode is a Submit button. I want to have a checkbox in each row of the table, to allow the user to select one or more rows to perform some action. I add the checkboxes as I load the table, naming them cbox[0], cbox[1], etc., and they appear on the form when it's loaded, but I don't know how to get the values into the $form array so that in my On Submit custom code I can determine which rows have been selected. Can anybody tell me what I'm missing here?
GreyHead 24 Feb, 2015
Hi nlheath,

If the HTML is valid then they should automatically be added to the $form->data array. What do you see in the Debugger when you add it?

Bob
nlheath 24 Feb, 2015
The debugger in the OnLoad shows an empty array - [cbox] =>
I click the boxes in the first 5 rows and click Submit.
In OnSubmit, if I don't use DataToSession and SessionToData, [cbox] is not listed at all.
If I use DataToSession and SessionToData, it shows as [cbox] =>
GreyHead 24 Feb, 2015
Hi nlheath,

Then I'd guess that your checkboxes aren't inside the <form> </form> tags - or aren't valid HTML ???

Please post a link to the form so I can take a quick look.

Bob
nlheath 24 Feb, 2015
Here's the code for the checkboxes:

<td>
<input type="checkbox" name="cbox[<?php echo $rowx; ?>]" value="0">
</td>

The cbox array was showing in the debugger only because I had a statement adding it to the $form->data array. When I remove that statement it no longer appears in either debugger.
nlheath 24 Feb, 2015
Here is a link to the form:
http://www.bucksgen.org/index.php/component/chronoforms?chronoform=BCGSMemberSelectTest&action=&EM
nlheath 24 Feb, 2015
I found what I was doing wrong. The code to load the table was in a Custom Code action, but it needed to be in a Custom Element.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger