| @@ -1,91 +1,101 @@ | ||
| 1 | -<?php | |
| 2 | -class AccuaForm_View_Standard extends View { | |
| 3 | - public function render() { | |
| 4 | - echo '<form', $this->form->getAttributes(), '>'; | |
| 5 | - $this->form->getError()->render(); | |
| 6 | - | |
| 7 | - $elements = $this->form->getElements(); | |
| 8 | - $elementSize = sizeof($elements); | |
| 9 | - $elementCount = 0; | |
| 10 | - for($e = 0; $e < $elementSize; ++$e) { | |
| 11 | - $element = $elements[$e]; | |
| 12 | - | |
| 13 | - if($element instanceof Element_Hidden || $element instanceof Element_HTMLExternal) { | |
| 14 | - $element->render(); | |
| 15 | - } elseif($element instanceof Element_Button) { | |
| 16 | - if($e == 0 || !$elements[($e - 1)] instanceof Element_Button) | |
| 17 | - echo '<div class="pfbc-element pfbc-buttons">'; | |
| 18 | - $element->render(); | |
| 19 | - if(($e + 1) == $elementSize || !$elements[($e + 1)] instanceof Element_Button) | |
| 20 | - echo '</div>'; | |
| 21 | - } else { | |
| 22 | - echo '<div class="pfbc-element-', $elementCount, ' pfbc-element">', $element->getPreHTML(); | |
| 23 | - $this->renderLabel($element); | |
| 24 | - if ($element instanceof Element_HTML) { | |
| 25 | - $element->render(); | |
| 26 | - } else { | |
| 27 | - echo '<div class="pfbc-fieldwrap">'; | |
| 28 | - $element->render(); | |
| 29 | - echo '</div>'; | |
| 30 | - } | |
| 31 | - echo $element->getPostHTML(), '<div class="pfbc-elementbottom"></div></div>'; | |
| 32 | - ++$elementCount; | |
| 33 | - } | |
| 34 | - } | |
| 35 | - | |
| 36 | - echo '</form>'; | |
| 37 | - } | |
| 38 | - | |
| 39 | - /*This method encapsulates the various pieces that are included in an element's label.*/ | |
| 40 | - protected function renderLabel($element) { | |
| 41 | - $label = $element->getLabel(); | |
| 42 | - $id = $element->getID(); | |
| 43 | - $description = $element->getDescription(); | |
| 44 | - if(!empty($label) || !empty($description)) { | |
| 45 | - echo '<div class="pfbc-label">'; | |
| 46 | - if(!empty($label)) { | |
| 47 | - echo '<label for="', $id, '">', $label; | |
| 48 | - if($element->isRequired()) | |
| 49 | - echo ' <strong>*</strong>'; | |
| 50 | - echo '</label>'; | |
| 51 | - } | |
| 52 | - if(!empty($description)) | |
| 53 | - echo '<em>', $description, '</em>'; | |
| 54 | - echo '</div>'; | |
| 55 | - } | |
| 56 | - } | |
| 57 | - | |
| 58 | - public function renderCSS() { | |
| 59 | - $id = $this->form->getId(); | |
| 60 | - $width = $this->form->getWidth(); | |
| 61 | - $widthSuffix = $this->form->getWidthSuffix(); | |
| 62 | - $this->form->renderCSS(); | |
| 63 | -/* | |
| 64 | - parent::renderCSS(); | |
| 65 | - echo <<<CSS | |
| 66 | -#$id { width: $width{$widthSuffix}; } | |
| 67 | -#$id .pfbc-element { margin-bottom: .6em } | |
| 68 | -#$id .pfbc-label { margin-bottom: .2em; } | |
| 69 | -#$id .pfbc-label label { display: block; } | |
| 70 | -#$id .pfbc-textbox, #$id .pfbc-textarea, #$id .pfbc-select { width: 98% !important; display:block; border: 1px solid #ccc; padding:2px; } | |
| 71 | -#$id .pfbc-fieldwrap { width: $width{$widthSuffix}; display: inline-block; } | |
| 72 | -#$id .pfbc-buttons { text-align: right; } | |
| 73 | -CSS; | |
| 74 | - | |
| 75 | - $elements = $this->form->getElements(); | |
| 76 | - $elementSize = sizeof($elements); | |
| 77 | - $elementCount = 0; | |
| 78 | - for($e = 0; $e < $elementSize; ++$e) { | |
| 79 | - $element = $elements[$e]; | |
| 80 | - $elementWidth = $element->getWidth(); | |
| 81 | - if(!$element instanceof Element_Hidden && !$element instanceof Element_HTMLExternal && !$element instanceof Element_HTMLExternal) { | |
| 82 | - if(!empty($elementWidth)) { | |
| 83 | - echo '#', $id, ' .pfbc-element-', $elementCount, ' { width: ', $elementWidth, $widthSuffix, '; }'; | |
| 84 | - echo '#', $id, ' .pfbc-element-', $elementCount, ' .pfbc-textbox, #', $id, ' .pfbc-element-', $elementCount, ' .pfbc-textarea, #', $id, ' .pfbc-element-', $elementCount, ' .pfbc-select { width: ', $elementWidth, $widthSuffix, '; }'; | |
| 85 | - } | |
| 86 | - $elementCount++; | |
| 87 | - } | |
| 88 | - } */ | |
| 89 | - | |
| 90 | - } | |
| 91 | -} | |
| 1 | +<?php | |
| 2 | +class AccuaForm_View_Standard extends View { | |
| 3 | + public function render() { | |
| 4 | + echo '<form', $this->form->getAttributes(), '>'; | |
| 5 | + $this->form->getError()->render(); | |
| 6 | + | |
| 7 | + $elements = $this->form->getElements(); | |
| 8 | + $elementCount = 0; | |
| 9 | + $inButtonGroup = false; | |
| 10 | + | |
| 11 | + foreach($elements as $element) { | |
| 12 | + if($element instanceof Element_Hidden || $element instanceof Element_HTMLExternal) { | |
| 13 | + $element->render(); | |
| 14 | + } elseif($element instanceof Element_Button) { | |
| 15 | + if (!$inButtonGroup) { | |
| 16 | + echo '<div class="pfbc-element pfbc-buttons">'; | |
| 17 | + $inButtonGroup = true; | |
| 18 | + } | |
| 19 | + $element->render(); | |
| 20 | + } else { | |
| 21 | + if ($inButtonGroup) { | |
| 22 | + echo '</div>'; | |
| 23 | + $inButtonGroup = false; | |
| 24 | + } | |
| 25 | + if ($element instanceof AccuaForm_Element_FieldsetBegin || $element instanceof AccuaForm_Element_FieldsetEnd) { | |
| 26 | + $element->render(); | |
| 27 | + } else { | |
| 28 | + echo '<div class="pfbc-element-', $elementCount, ' pfbc-element">', $element->getPreHTML(); | |
| 29 | + $this->renderLabel($element); | |
| 30 | + if ($element instanceof Element_HTML) { | |
| 31 | + $element->render(); | |
| 32 | + } else { | |
| 33 | + echo '<div class="pfbc-fieldwrap">'; | |
| 34 | + $element->render(); | |
| 35 | + echo '</div>'; | |
| 36 | + } | |
| 37 | + echo $element->getPostHTML(), '<div class="pfbc-elementbottom"></div></div>'; | |
| 38 | + ++$elementCount; | |
| 39 | + } | |
| 40 | + } | |
| 41 | + } | |
| 42 | + | |
| 43 | + if ($inButtonGroup) { | |
| 44 | + echo '</div>'; | |
| 45 | + $inButtonGroup = false; | |
| 46 | + } | |
| 47 | + | |
| 48 | + echo '</form>'; | |
| 49 | + } | |
| 50 | + | |
| 51 | + /*This method encapsulates the various pieces that are included in an element's label.*/ | |
| 52 | + protected function renderLabel($element) { | |
| 53 | + $label = $element->getLabel(); | |
| 54 | + $id = $element->getID(); | |
| 55 | + $description = $element->getDescription(); | |
| 56 | + if(!empty($label) || !empty($description)) { | |
| 57 | + echo '<div class="pfbc-label">'; | |
| 58 | + if(!empty($label)) { | |
| 59 | + echo '<label for="', $id, '">', $label; | |
| 60 | + if($element->isRequired()) | |
| 61 | + echo ' <strong>*</strong>'; | |
| 62 | + echo '</label>'; | |
| 63 | + } | |
| 64 | + if(!empty($description)) | |
| 65 | + echo '<em>', $description, '</em>'; | |
| 66 | + echo '</div>'; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + public function renderCSS() { | |
| 71 | + $id = $this->form->getId(); | |
| 72 | + $width = $this->form->getWidth(); | |
| 73 | + $widthSuffix = $this->form->getWidthSuffix(); | |
| 74 | + $this->form->renderCSS(); | |
| 75 | +/* | |
| 76 | + parent::renderCSS(); | |
| 77 | + echo <<<CSS | |
| 78 | +#$id { width: $width{$widthSuffix}; } | |
| 79 | +#$id .pfbc-element { margin-bottom: .6em } | |
| 80 | +#$id .pfbc-label { margin-bottom: .2em; } | |
| 81 | +#$id .pfbc-label label { display: block; } | |
| 82 | +#$id .pfbc-textbox, #$id .pfbc-textarea, #$id .pfbc-select { width: 98% !important; display:block; border: 1px solid #ccc; padding:2px; } | |
| 83 | +#$id .pfbc-fieldwrap { width: $width{$widthSuffix}; display: inline-block; } | |
| 84 | +#$id .pfbc-buttons { text-align: right; } | |
| 85 | +CSS; | |
| 86 | + | |
| 87 | + $elements = $this->form->getElements(); | |
| 88 | + $elementCount = 0; | |
| 89 | + foreach ($elements as $element) { | |
| 90 | + $elementWidth = $element->getWidth(); | |
| 91 | + if(!$element instanceof Element_Hidden && !$element instanceof Element_HTMLExternal && !$element instanceof Element_HTMLExternal) { | |
| 92 | + if(!empty($elementWidth)) { | |
| 93 | + echo '#', $id, ' .pfbc-element-', $elementCount, ' { width: ', $elementWidth, $widthSuffix, '; }'; | |
| 94 | + echo '#', $id, ' .pfbc-element-', $elementCount, ' .pfbc-textbox, #', $id, ' .pfbc-element-', $elementCount, ' .pfbc-textarea, #', $id, ' .pfbc-element-', $elementCount, ' .pfbc-select { width: ', $elementWidth, $widthSuffix, '; }'; | |
| 95 | + } | |
| 96 | + $elementCount++; | |
| 97 | + } | |
| 98 | + } */ | |
| 99 | + | |
| 100 | + } | |
| 101 | +} | |