Example #1
0
 /**
  * Add a selection drop down for the month and date to be selected.
  * @param string $name The name of the selection element
  * @param I2CE_Date $default The default I2CE_Date object to use to preset the value.
  * @param boolean $showError A flag if this field is currently invalid to mark it as such.
  * @param DOMNode $node The node to append the element to.
  * @param boolean $hidden Set to true if the form element should be hidden. Defaults to false
  * @param boolean $blank Set to true if this element should have a blank entry option. Defaults to false.
  */
 public static function addMonthDayElement($template, $name, $default, $showError, $node, $hidden = false, $blank = false)
 {
     if ($hidden) {
         $day = $template->createElement("input", array("name" => $name . "[day]", "type" => "hidden", "value" => $default->day()));
         $month = $template->createElement("input", array("name" => $name . "[month]", "type" => "hidden", "value" => $default->month()));
     } else {
         $day = $template->createElement("select", array("name" => $name . "[day]", "class" => "date_day" . ($showError ? "_error" : "")));
         if ($blank) {
             $blank_opt = $template->createElement("option", array("value" => "", "class" => "blank_opt"), "Select");
             $day->appendChild($blank_opt);
         }
         for ($i = 1; $i <= 31; $i++) {
             $opt = $template->createElement("option", array("value" => $i), $i);
             if ($i == $default->isDay($i)) {
                 $opt->setAttribute("selected", "selected");
             }
             $day->appendChild($opt);
         }
         $month = $template->createElement("select", array("name" => $name . "[month]", "id" => $name, "class" => "date_month" . ($showError ? "_error" : "")));
         if ($blank) {
             $blank_opt = $template->createElement("option", array("value" => "", "class" => "blank_opt"), "Select");
             $month->appendChild($blank_opt);
         }
         foreach (I2CE_Date::$months as $mon => $def_name) {
             $mon_name = $default->getMonthName($mon);
             $opt = $template->createElement("option", array("value" => $mon, "class" => $mon == "" ? "blank_opt" : ""), $mon_name);
             if ($default->isMonth($mon)) {
                 $opt->setAttribute("selected", "selected");
             }
             $month->appendChild($opt);
         }
     }
     $node->appendChild($day);
     $node->appendChild($month);
 }