PHP Classes
elePHPant
Icontem

File: src/Renderer/FormRenderer.php

Recommend this page to a friend!
  Classes of Derek McLean  >  HTML Forms  >  src/Renderer/FormRenderer.php  >  Download  
File: src/Renderer/FormRenderer.php
Role: Class source
Content type: text/plain
Description: Class source
Class: HTML Forms
Generate and validate submitted HTML forms
Author: By
Last change:
Date: 10 months ago
Size: 1,159 bytes
 

Contents

Class file image Download
<?php
/**
 * User: delboy1978uk
 * Date: 29/11/2016
 * Time: 19:44
 */

namespace Del\Form\Renderer;

use
Del\Form\Field\CheckBox;
use
Del\Form\Field\Radio;
use
DOMElement;
use
DOMText;

class
FormRenderer extends AbstractFormRenderer implements FormRendererInterface
{
   
/**
     * @return DOMElement
     */
   
public function renderFieldLabel()
    {
       
$label = $this->createLabelElement();
       
$text = new DOMText($this->field->getLabel());
       
$label->appendChild($text);
        return
$label;
    }

   
/**
     * @return DomElement
     */
   
public function renderFieldBlock()
    {
       
// Set form group div properties
       
$formGroup = $this->block;
       
$class = $formGroup->getAttribute('class').'form-group';
       
$formGroup->setAttribute('class', $class);
       
$formGroup->setAttribute('id', $this->field->getName().'-form-group');

       
$formGroup->appendChild($this->label);

       
$formGroup->appendChild($this->element);

        if (!
is_null($this->errors)) {
           
$formGroup->appendChild($this->errors);
        }

       
// Field rendered! Pass it back!
       
return $formGroup;
    }

}