开发者

Create dropdown from multi array + PHP class

Well, I am writing class that creates a DOB selection dropdown. I am having figure out the dropdown(), it seems working but not exactly. Code just creates one drop down, and under this dropdown all day, month and year data are in one selection. like:

<label>
<sup>*</sup>DOB</label>
<select name="form_bod_year">
<option value=""/>
<option selected="" value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
<option value="3">4</option>
<option value="4">5</option>
<option value="5">6</option>
..
<option value="29">30</option>
<option value="30">31</option>
<option value="1">January</option>
<option value="2">February</option>
..
<option value="11">November</option>
<option value="12">December</option>
<option selected="" value="0">1910</option>
<option value="1">1911</option>
..
<option value="98">2008</option>
<option value="99">2009</option>
<option value="100">2010</option>
</select>

Here is my code, I wonder that why all datas are in one selection. It has to be tree selction - Day:Month:Year.

//dropdown connector
class DropDownConnector
{
  var $dropDownsDatas;
  var $field_label;
  var $field_name;
  var $locale;

function __construct($dropDownsDatas, $field_label, $field_name, $locale) { $this->dropDownsDatas = $dropDownsDatas; $this->field_label = $field_label; $this->field_name = $field_name; $this->locale = $locale; } function getValue(){ return $_POST[$this->field_name]; } function dropdown(){ $selectedVal = $this->getValue($this->field_name); foreach($this->dropDownsDatas as $keys=>$values){ 开发者_如何转开发 foreach ($values as $key=>$value){ $selected = ($key == $selectedVal ? "selected" : "" ); $options .= sprintf('%s',$key,$value); }; }; return $select_start = "$this->field_desc".$options.""; } 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.''; } }

function generateForm ($lang,$country_list,$states_list,$days_of_month,$month_list,$years){ $xx = array( 'form_bod_day' => $days_of_month, 'form_bod_month' => $month_list, 'form_bod_year' => $years); echo $dropDownConnector = new DropDownConnector($xx,'DOB','bod','en-US'); }

// Call php class to use class on external functionss. $avInq = new formGenerator;

$lang='en-US'; echo generateForm ($lang,$country_list,$states_list,$days_of_month,$month_list,$years);


While this might or might not work for you, I would suggest taking a look at the Jquery UI Datepicker. It provides a very nice and highly customizable calendar that might be able to save you a lot of time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜