Hello,
Well, I keep improving my form generation classes and stuck in returning all the country elements in country_data array. Only first two elements is displaying on dropdown options.
Here is dropdown class:
//drop down form class class DropDown { function __construct ($form, $field_label, $field_name, $field_desc, $dropdown_data, $locale){ $this->form = $form; $this->field_label = $field_label; $this->field_name = $field_name; $this->field_desc = $field_desc; $this->dropdown_data = $dropdown_data; $this->locale = $locale; } function getNotRequiredData(){ global $notReqArry; return $notReqArry[$this->locale]; } function getValue(){ return $_POST[$this->field_name]; } function option(){ foreach ($this->dropdown_data as $key=>$value){ return $options = sprintf('%s',$key,$value); }; } function dropdown(){ return $select_start = "field_name\">$this->field_desc".$this->option().""; } function getLabel(){ $non_req = $this->getNotRequiredData(); $req = in_array($this->field_name, $non_req) ? '' : '*'; return $this->field_label ? $req . $this->field_label : ''; } function __toString(){ $id = $this->field_name; $label = $this->getLabel(); $field = $this->dropdown(); return 'field_name.'">'.$label.''.$field.''; } }
And I use extra function for extra options:
function generateForm ($lang,$country_list){ switch($lang) { case 'en-US': //create EN web form echo $countryField = new DropDown ($form, 'Country', 'form_country', '--Select Country--', $country_list, 'en-US'); break; case 'fr-FR': //create FR web form break; case 'de-DE': //create DE web form break; case 'ja-JP': //create JA web form break; default: //create default web form print('foooo'); }; }
And I call generateForm fun at the bottom of page.
$lang='en-US'; echo generateForm ($lang,$country_list);
At the previous question, one expert mentioned the $key and $value in foreach are not object, but I do not understand what I need to more logic on here. Yeah, I really new at PHP and just have short experience on AS. I need help.
Thanks.