Database Reference
In-Depth Information
str << "<br />" if vertical # display items vertically
end
return str
end
To fetch the cow accessory information and present it using checkboxes, do this:
acc_info = get_enumorset_info ( dbh , "cookbook" , "cow_order" , "accessories" )
if acc_info [ "default" ]. nil?
acc_def = []
else
acc_def = acc_info [ "default" ]. split ( "," )
end
form << make_checkbox_group ( "accessories" ,
acc_info [ "values" ] ,
acc_info [ "values" ] ,
acc_def ,
true ) # display items vertically
To display a scrolling list instead, invoke make_scrolling_list() :
form << make_scrolling_list ( "accessories" ,
acc_info [ "values" ] ,
acc_info [ "values" ] ,
acc_def ,
3 , # display 3 items at a time
true ) # create multiple-pick list
In PHP, fetch the accessory information:
$acc_info = get_enumorset_info ( $dbh , "cookbook" , "cow_order" , "accessories" );
$acc_def = explode ( "," , $acc_info [ "default" ]);
Then present checkboxes or a scrolling list:
print ( make_checkbox_group ( "accessories[]" ,
$acc_info [ "values" ],
$acc_info [ "values" ],
$acc_def ,
TRUE )); # display items vertically
print ( make_scrolling_list ( "accessories[]" ,
$acc_info [ "values" ],
$acc_info [ "values" ],
$acc_def ,
3 , # display 3 items at a time
TRUE )); # create multiple-pick list
Note that the field name in the PHP examples is specified as accessories[] rather than
as accessories . In PHP, to permit a field to have multiple values, you must add [] to
the name. If you omit the [] , the user can select multiple items while filling in the form,
but PHP returns only one to your script. This issue comes up again (see Recipe 20.5 )
when we discuss how to process the contents of submitted forms.
Search WWH ::




Custom Search