0
votes

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);
1
Just a note, you're using PHP5's __construct() but using the old fashioned var to declare variables. You should really just define them as public, in the new PHP5 way (or hide them with private or protected).alex
Man a wish I had a Birth of Day, all I have is my crappy Day of Birth :(Ben
out of interest - why don't you make the values in the dropdowns match the text values - that why you don't need any kind of maths to build the date string when the user submits.HorusKol
@Ben - Be nice. English clearly isn't his first language. I'd like to see you write perfectly in a foreign language.Kenaniah
@Kenaniah - It was meant to be a joke, not a reproach. BTW, English is not my native language neither.Ben

1 Answers

0
votes

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.