By: Jade
Date: 2016-02-26
Time: 19:08
|
Is one function per radio/checkbox really required?
Hello,
Thanks a lot for TBS. It's very helpful.
I need to have a form with many (~50) fields. It appears that the only way to work with TBS for form submission is as follows:
HTML Template:
<tr><td>State:</td><td>
<input type="radio" name="state_select[]" value="[state_blk.val;block=input;ondata=is_checked_state]" [state_blk.checked]>[state_blk.val]</input>
</tr>
<tr><td>Country:</td><td>
<input type="checkbox" name="cntry_select[]" value="[cntry_blk.val;block=input;ondata=is_checked_cntry]" [cntry_blk.checked]>[cntry_blk.val]</input>
</tr>
|
But this requires one function per radio/checkbox as each requires a separate global array. And manual says that onload cannot take extra parameter. Is thre some elegant solution for this task?
TIA
|
By: Skrol29
Date: 2016-03-01
Time: 00:54
|
Re: Is one function per radio/checkbox really required?
Hi,
I guess you mean « ondata cannot take extra parameter ».
Parameter "ondata" cannot take extra parameters because the custom function may be run for each record before the block is merged.
Nevertheless, the "ondata" custom function has an argument $BlockName that you can use for switching cases in the ondata common function.
|
By: Jade
Date: 2016-03-01
Time: 18:18
|
Re: Is one function per radio/checkbox really required?
Thanks a lot. I got it fixed as suggested.
function is_checked($block_name, &$curr_rec, $rec_num) {
if ($block_name == 'v1_blk') {
$list = &$GLOBALS['v1_list'];
$checked = $GLOBALS['v1_checked'];
} else if ($block_name == 'v2_blk') {
$list = &$GLOBALS['v2_list'];
$checked = $GLOBALS['v2_checked'];
}
if (in_array($curr_rec[val], $checked)) {
$curr_rec['checked'] = 'checked';
$list .= " " . $curr_rec[val];
} else {
$curr_rec['checked'] = '';
}
}
|
|
|
Posting in progress.
Please wait...
|