public function writeLabel() { // Writes label for form control $html = false; if (isset($this->labelText)) { if ($this->type == 'heading') { $html = "<label class=\"strong control-label "; if ($this->hasClass('centre')) { $html .= "text-center"; } $html .= "\">{$this->labelText}</label>"; } else { // Writes HTML for labelText $label = new HTMLLabel($this->labelText, $this->id); // instantiate at this point to ensure id available $label->addClass('control-label'); $html = $label->writeHTML(); } } return $html; }
<body> <?php $form = new HTMLForm('form_1'); $divNome = new HTMLDIV('d_nome'); $form->setMethod('POST'); $form->setAction($_SERVER['SCRIPT_NAME']); $label = new HTMLLabel('Nome', 'i_nome'); $inputNome = new HTMLInput('text', 'i_nome'); $inputNome->addAttribute('value', "Evandro Pereira de Lacerda"); $inputNome->addAttribute('size', 60); $text = new HTMLTextNode('Nome'); $label->addChild($inputNome); $divNome->addChild($label); //*************************************************** $divNascimento = new HTMLDIV('d_nasc'); $labelNascimento = new HTMLLabel("Data de Nascimento", 'i_nasc'); $nascimento = new HTMLInput('date', 'i_nasc'); $nascimento->addAttribute('size', 25); $nascimento->addClass('input_n'); $nascimento->addClass('input_md'); $labelNascimento->addChild($nascimento); $divNascimento->addChild($labelNascimento); //*************************************************** $arrayOptions = ['Corsa', 'Fiesta', 'Cobalt', 'Onix', 'Escort', 'Ipanema', 'Uno', 'Palio', 'Gol', 'Verona']; $select = new HTMLSelect('carros'); foreach ($arrayOptions as $opt) { if ($opt === 'Fiesta') { $select->addChild(new HTMLOption($opt, $opt, true)); } else { $select->addChild(new HTMLOption($opt, $opt)); }