Categories > TinyButStrong general >

Checkbox - how to feed and select?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: Col
Date: 2011-05-17
Time: 07:57

Checkbox - how to feed and select?

I have searched the forums and tried all sorts of combinations of the 'Selecting Items' example but I can't work out how to feed and select a list of check boxes. Some code which will hopefully highlight what I'm trying to do:

example.php
$cbChecked = $_POST['cbSelected'];
$checkboxes = array('checkbox1', 'checkbox2', 'checkbox3','checkbox4'); // actually this array comes from a database query so the contents will vary

$tbs->LoadTemplate('example.html');
$tbs->MergeBlock('cbblk', $checkboxes);
$tbs->Show();

example.html
<snip>
<form action="[var..script_name]" method="POST">
<strong>Checkbox choices</strong><br>
<input type="checkbox" name="cbSelected[]" value="[cbblk.val;block=input]">[cbblk.val]<br></input>
</form>
</snip>

From the example I should put [onshow.cbChecked;ope=html;select=cbSelected] in the html file somewhere. Whenever I do the browser just times out. Any advice greatly appreciated.

Col
By: Col
Date: 2011-05-18
Time: 01:58

Re: Checkbox - how to feed and select?

I have worked around this problem by using ondata. For anybody else coming across this problem here is my solution.

example.php
$cbChecked = $_POST['cbSelected'];
$checkboxes = array('checkbox1', 'checkbox2', 'checkbox3','checkbox4'); // actually this array comes from a database query so the contents will vary

$tbs->LoadTemplate('example.html');
$tbs->MergeBlock('cbblk', $checkboxes);
$tbs->Show();

function isChecked($BlockName, &$CurrRec, $RecNum) {
    global $cbChecked;

    if (in_array($CurrRec[val], $cbChecked))
        $CurrRec['checked'] = 'checked';
    else
        $CurrRec['checked'] = '';
}

example.html
<snip>
<form action="[var..script_name]" method="POST">
<strong>Checkbox choices</strong><br>
<input type="checkbox" name="cbSelected[]" value="[cbblk.val;block=input;ondata=isChecked]" [cbblk.checked]>[cbblk.val]<br></input>
</form>
</snip>

If there is a solution more in line with the 'Selecting Items' example I would be interested to hear it.

Col