Posted by michal
2013-10-29

Hi
I have version 1.17, how do i change a input field to dropdown listbox, this dropdown read the values from a mysql table i the same mysql database?
Posted by Tom
2013-10-29

Hi Michal,
This is an example for converting a text field to a dropdown list box, which gets options from a table in the database. I'll use the "country" field in this example.

(1) Create a table to store country names. Use the following sql statement to create the country table ( and add some country names to the table. )
CREATE TABLE `tbl_country` (
`country_id` int(11) NOT NULL AUTO_INCREMENT,
`country_name` varchar(100) DEFAULT NULL,
PRIMARY KEY (`country_id`)
) ENGINE=MyISAM;
(2) Replace the country field definition in web/codelib/asc/df.fl.address.inc.php with the following:
'country'=>array(
XA_CLASS=>'cls_country',
XA_CAPTION=>RSTR_COUNTRY,
XA_REQUIRED=>false,
XA_SELECT_ON_TOP=>STR_SELECT_CAPTION,
XA_MIN_CHAR=>0,
XA_MAX_CHAR=>64,
XA_SEARCH_OP=>'s=',
XA_LIST=>'(sp)(sr)(fd)'
),
(3) Add this class to web/codelib/asc/cls_fl_address.inc.php.
//----------------------------------------------------------------
// cls_country
//----------------------------------------------------------------
class cls_country extends CVSelection
{
function GetText( &$msg )
{
return $this->Populate(
$msg,
"tbl_country",
array( "country_id", "country_name" ),
array(),
"country_id ASC"
);
}
}
Done!