Class HtmlElement
Direct known subclasses
Indirect known subclasses
Copyright: 2004-2016 The Admidio Team
License: GNU General Public License v2.0 only **********************************************************************************************
Brief:
This @b abstract @b class parses html elements
This abstract class is designed to parse html elements. It is only allowed to use extensions of this class. Create a html object and add your elements programmatically . Calling as parent instance just define the element you need and add all inline elements or child elements. Also it is possible to define attributes and value for each added element. Content data can be passed as string or as array. The class supports also reading the data from assoc arrays and bi dimensional arrays.
Class: HtmlElement
Code:
// Example content arrays $dataArray = array('Data 1', 'Data 2', 'Data 3');
Code:
// create as parent instance parent::HtmlElement('ul','class', 'unordered'); // Parameters( element, attribute, value, nesting (true/false )) // we want to have further attributes for the element and set an id, for example HtmlElement::addAttribute('id','mainelement'); // set a list element with content as string HtmlElement::addElement('li', 'list 1'); // if you need attributes for your setted element then first define the element, set the attributes and after that // pass the content. // Example: Arrays are also supported for content values. HtmlElement::addElement('li'); HtmlElement::addAttribute('class', 'from array'); HtmlElement::addData($dataArray); // As result you get 3
Code:
// Creating block elements with nested divs. // Example using nesting mode for html elements // Setting mode to true you are allowed to set the main element ('div' in this example) further times // Default false it is not possible to set the main element again
parent::HtmlElement ('div', 'class', 'pagewrap', true); // now we can nest a second div element with a paragaph. // Because of div is the parent of the paragraph element, we must tell the class using method addParentElement(); HtmlElement::addParentElement('div'); // We want to set an Id for the div element, for example HtmlElement::addAttribute('id', 'Paragraphs', 'div'); // Define a paragrph HtmlElement::addElement('p', 'Hello World'); // Nested div element must be closed ! HtmlElement::closeParentElement('div'); // Get the block element $htmlBlock = HtmlElement::getHtmlElement(); echo $htmlBlock;
Code:
parent::HtmlElement(); HtmlElement::addElement('a'); HtmlElement::addAttribute('href', 'http://www.admidio.org'); HtmlElement::addData('Admidio Homepage'); $hyperlink = HtmlElement::getHtmlElement(); echo $hyperlink;
Code:
// Create a form element parent::HtmlElement('form', 'name', 'testform'); HtmlElement::addAttribute('action', 'test.php'); HtmlElement::addAttribute('method', 'post'); HtmlElement::addAttribute('enctype', 'text/html'); // add an input field with label HtmlElement::addElement('input'); HtmlElement::addAttribute('type', 'text'); HtmlElement::addAttribute('name', 'input'); HtmlElement::addHtml('Inputfield:'); // pass a whitespace because element has no content HtmlElement::addData(' ', true); // true for self closing element (default: false) // add a checkbox HtmlElement::addElement('input'); HtmlElement::addAttribute('type', 'checkbox'); HtmlElement::addAttribute('name', 'checkbox'); HtmlElement::addHtml('Checkbox:'); // pass a whitespace because element has no content HtmlElement::addData(' ', true); // true for self closing element (default: false) // add a submit button HtmlElement::addElement('input'); HtmlElement::addAttribute('type', 'submit'); HtmlElement::addAttribute('value', 'submit'); // pass a whitespace because element has no content HtmlElement::addData(' ', true);
echo HtmlElement::getHtmlElement();
Endcode
Endcode
Endcode
Endcode
Endcode
Par: Testarray with data
Par: Example_1: @b unorderedlist
Par: Example_2 Nested Div Elements using nesting mode
Par: Example_3 Hyperlinks
Par: Example_4 Form element
Located at htmlelement.php
Methods summary
public
|
#
__construct( string $element, boolean $nesting = false )
Constructor initializing all class variables |
public
|
#
addAttribute( string $attrKey, string $attrValue, string $element = null )
Add attributes to the selected element. If that attribute is already added than the new value will be attached to the current value. |
protected
|
|
public
|
|
public
|
#
addElement( string $childElement, string $attrKey = '', string $attrValue = '', string $data = '', boolean $selfClosing = false )
|
public
|
|
public
|
|
public
boolean
|
|
private
string
|
#
getElementAttributesString( array $elementAttributes )
Create a valid html compatible string with all attributes and their values of the given element. |
private
string
|
#
getCurrentElementAttributesString( )
Create a valid html compatible string with all attributes and their values of the last added element. |
private
string
|
#
getMainElementAttributesString( )
Create a valid html compatible string with all attributes and their values of the main element. |
public
string
|
Properties summary
protected
|
$nesting
|
|
protected
|
$mainElement
|
|
protected
|
$mainElementAttributes
|
|
protected
|
$mainElementWritten
|
|
protected
|
$currentElement
|
|
protected
|
$currentElementAttributes
|
|
protected
|
$currentElementDataWritten
|
|
protected
|
$htmlString
|
|
protected
|
$parentFlag
|
|
protected
|
$arrParentElements
|