コード例 #1
0
ファイル: Select.php プロジェクト: HaldunA/phpwebsite
 /**
  * Returns a select tag wrapped around its option tags.
  * @return string
  */
 public function __toString()
 {
     $options = array();
     $groups = array();
     $suboptions = array();
     if ($this->first_blank) {
         $options[] = new Option('', '');
     }
     foreach ($this->options as $opt) {
         if ($opt->hasOptgroup()) {
             $groups[$opt->getOptgroup()][] = $opt;
         } else {
             $options[] = (string) $opt;
         }
     }
     if (!empty($groups)) {
         foreach ($groups as $optgroup => $group) {
             $suboptions[] = "<optgroup label=\"{$optgroup}\">";
             $suboptions[] = implode("\n", $group);
             $suboptions[] = '</optgroup>';
         }
         if (!empty($options)) {
             $options = array_merge($suboptions, $options);
         } else {
             $options =& $suboptions;
         }
     }
     $option_string = implode("\n", $options);
     $this->setText($option_string);
     return parent::__toString();
 }
コード例 #2
0
ファイル: Checkbox.php プロジェクト: HaldunA/phpwebsite
 /**
  * Before using the parent setName function, this method adds missing
  * square brackets
  *
  * @param string $name
  */
 public function setName($name)
 {
     if (!preg_match('/\\[\\w*\\]$/', $name)) {
         $name .= '[]';
     }
     parent::setName($name);
 }