Example #1
0
<?php

require_once '../../bootstrap.php';
use Pop\Dom\Child;
use Pop\Dom\Dom;
try {
    $title = new Child('title', 'This is the title');
    $meta = new Child('meta');
    $meta->setAttributes(array('http-equiv' => 'Content-Type', 'content' => 'text/html; charset=utf-8'));
    $head = new Child('head');
    $head->addChildren(array($title, $meta));
    $h1 = new Child('h1', 'This is a header');
    $p = new Child('p', 'This is a paragraph.');
    $div = new Child('div');
    $div->setAttributes('id', 'contentDiv');
    $div->addChildren(array($h1, $p));
    $body = new Child('body');
    $body->addChild($div);
    $html = new Child('html');
    $html->setAttributes(array('xmlns' => 'http://www.w3.org/1999/xhtml', 'xml:lang' => 'en'));
    $html->addChildren(array($head, $body));
    $doc = new Dom(Dom::XHTML11, 'utf-8', $html);
    $doc->render();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
Example #2
0
 /**
  * Method to render the form using a basic 1:1 DT/DD layout
  *
  * @return void
  */
 protected function renderWithoutTemplate()
 {
     // Initialize properties.
     $this->output = null;
     $children = $this->form->getChildren();
     $this->form->removeChildren();
     $id = null !== $this->form->getAttribute('id') ? $this->form->getAttribute('id') . '-field-group-' : 'pop-form-field-group-';
     // Create DL element.
     $i = 1;
     $dl = new Child('dl', null, null, false, $this->form->getIndent());
     $dl->setAttributes('id', $id . $i);
     // Loop through the children and create and attach the appropriate DT and DT elements, with labels where applicable.
     foreach ($children as $child) {
         if ($child->getNodeName() == 'fieldset') {
             $chdrn = $child->getChildren();
             if (isset($chdrn[0])) {
                 $attribs = $chdrn[0]->getAttributes();
             }
         } else {
             $attribs = $child->getAttributes();
         }
         $name = isset($attribs['name']) ? $attribs['name'] : '';
         $name = str_replace('[]', '', $name);
         if (count($this->groups) > 0) {
             if (isset($this->groups[$i]) && $this->groups[$i] == $name) {
                 $this->form->addChild($dl);
                 $i++;
                 $dl = new Child('dl', null, null, false, $this->form->getIndent());
                 $dl->setAttributes('id', $id . $i);
             }
         }
         // Clear the password field from display.
         if ($child->getAttribute('type') == 'password') {
             $child->setValue(null);
             $child->setAttributes('value', null);
         }
         // If the element label is set, render the appropriate DT and DD elements.
         if (null !== $child->getLabel()) {
             // Create the DT and DD elements.
             $dt = new Child('dt', null, null, false, $this->form->getIndent() . '    ');
             $dd = new Child('dd', null, null, false, $this->form->getIndent() . '    ');
             // Format the label name.
             $lblName = $child->getNodeName() == 'fieldset' ? '1' : '';
             $label = new Child('label', $child->getLabel(), null, false, $this->form->getIndent() . '        ');
             $label->setAttributes('for', $name . $lblName);
             $labelAttributes = $child->getLabelAttributes();
             if (null !== $labelAttributes) {
                 foreach ($labelAttributes as $a => $v) {
                     $label->setAttributes($a, $v);
                 }
             } else {
                 if ($child->isRequired()) {
                     $label->setAttributes('class', 'required');
                 }
             }
             // Add the appropriate children to the appropriate elements.
             $dt->addChild($label);
             $child->setIndent($this->form->getIndent() . '        ');
             $childChildren = $child->getChildren();
             $child->removeChildren();
             foreach ($childChildren as $cChild) {
                 $cChild->setIndent($this->form->getIndent() . '            ');
                 $child->addChild($cChild);
             }
             $dd->addChild($child);
             $dl->addChildren(array($dt, $dd));
             // Else, render only a DD element.
         } else {
             $dd = new Child('dd', null, null, false, $this->form->getIndent() . '    ');
             $child->setIndent($this->form->getIndent() . '        ');
             $dd->addChild($child);
             $dl->addChild($dd);
         }
     }
     // Add the DL element and its children to the form element.
     $this->form->addChild($dl);
     $this->output = $this->form->render(true);
 }