Gossamer Forum
Home : General : Perl Programming :

custom checkbox form input

Quote Reply
custom checkbox form input
i'm working on a form for a client who wants several checkboxes for one field and user can select 1 or more. i need the selections joined with a delimiter and written to a database. the user can modify the record later, so i also need to read the database, split the selections, and show checkmarks in the previously selected items. i'm working in dbman, but thought this might be more appropriate to post in this forum because it seems complicated (to me, at least).

here's what i've tried (excerpted relevant parts only):
in build_record_form:
my (@pref);
print &build_checkbox_custom('Preference','Pre-planning','pref[0]'); print qq|Pre-planning|;
print qq| <BR><strong>Booth set-up</strong><BR>|;
print &build_checkbox_custom('Preference','Booth set-up Friday before 3pm','pref[1]'); print qq|Friday, I can arrive before
3pm<br>|;
print &build_checkbox_custom('Preference','Booth set-up Friday 3 - 8pm','pref[2]'); print qq|Friday 3 - 8pm</TD></TR>

then in modify_record:
my ($i, $tmp);
for ($i = 0; $i <= 2; $i++) {
if ($pref[$i]) {
$tmp .= $pref[$i] . '~~';
}
}
$rec{'Preference'} = $tmp;


i used array @pref to capture the individual checkboxes. the "real" fieldname is Preference, which is a required field. in modify record, i was trying to join $pref[0] - $pref[2] with ~~ delimiter. i figure add record will be easy, if i can figure out modify record.

what's happening - Preference has no value so i'm getting error that it can't be blank. with debug on i can see that my values for pref[0] and pref[2] are correct so for some reason they are not being joined into Preference.

eventually, there will be about 10 choices for the Preference field. i'm testing with just 3 now till i can get it working. HELP!!!!!! thanks!
Quote Reply
Re: [delicia] custom checkbox form input In reply to
don't know why i made this so difficult on myself. all i needed to do was use the same fieldname and generate each checkbox separately instead of the build_checkbox routine in dbman.