ar\html

ar\html\form A simple way to create and validate html forms.
ar\html\menu A simple menu builder.
ar\html\table A simple data table builder.

This is a basic HTML generation and manipulation module, based on ar/xml. It can be configured to either output HTML or XHTML.

Example:

<pinp>
echo ar('html')->form( array(
'foo' => 'bar',
'password' => array(
'label' => 'Your password:',
'type' => 'password'
)
) );
</pinp>

Results in:

<form method="POST"> 
  <div class="field text">
    <label>bar</label>
    <input type="text" name="foo" id="foo" value="">
  </div>
<div class="field password">
    <label>Your password:</label>
    <input type="password" name="password" id="password" value="">
  </div>
<div class="formButtons">
    <input type="submit" name="button_0" value="Ok">
  </div>
</form>

methods

(string) attribute Generates a HTML attribute for inclusion in an HTML tag. See ar_xml::attribute.
(string) attributes Generates a string of attributes for inclusion in an HTML tag. See ar_xml::attributes.
(object) comment Generates a html comment. See ar_xml::comment.
(void) configure Allows you to configure a number of HTML writer options.
(string) indent Indents the given HTML content. See ar_xml::indent
(object) doctype Generates a valid doctype.
(object) form A simple html form builder.
(object) menu A simple html menu builder.
(string) name Generates a valid HTML name. See ar_xml::name.
(object) el Returns an HTML element with the given tagName, attributes and child nodes. Replaces ar_html::tag() in Ariadne > 2.7.3.
(object) element Identical to ar_html::el().
(object) nodes Generates a list of nodes. See ar_xml::nodes.
(object) parse Parses a string of HTML and returns an HTML dom object.
(object) table A data table builder.
(object) tag Returns a HTML tag with the given name, attributes and children. Deprecated in Ariadne > 2.7.3.
(string) value Returns a valid HTML value. See ar_xml::value.

configure

(void) ar('html')->configure( $option, $value )

Configures a global HTML option. Currently supported:

(bool) comments Strips comments if false, default is true.
(mixed) indent Can be set to true (indent the HTML code) or false (do not indent the HTML code) or a string to indent the HTML with.
(bool) preserveWhiteSpace If true, text nodes containing only white space will be preserved when parsing HTML. Set indent to false to correctly output the HTML again.
(bool) xhtml If true, the generated HTML will be in XHTML format.

doctype

(object) ar('html')->doctype( $type = 'strict', $quirksmode = false )

(string) $type The type of the DTD to use, can be either 'strict', 'transitional', 'frameset' or a fully qualified DTD string. e.g.: '"http://www.w3.org/TR/html4/strict.dtd"'.
(bool) $quirksmode If true, the DTD string will be skipped from the Doctype, triggering quirksmode in most browsers.

Generates an ar_htmlNode object with the html doctype string for either HTML 4.01 or XHTML 1.0, depending on the xhtml configuration setting. The ar_htmlNode class is identical to the ar_xmlNode class.

form

(object) ar('html')->form( $formFields, $buttons = null, $action = null, $method = 'POST' )

(array) $formFields An array of form fields.
(array) $buttons An array with buttons. If not set, the default is 'Ok' and 'Cancel'.
(string) $action The action attribute of the form tag.
(string) $method The method of the form tag, e.g. 'POST' or 'GET'.

This method returns a new ar_html_form object. This can be used to print a form or to validate it.

menu

Ariadne up to 2.7.5:

(object) ar('html')->menu( $attributes = null, $list = null )

(array) $attributes A list of attributes for the menu object ( <ul> ).
(mixed) $list Either an array of menu items or an ariadne query object.

Ariadne > 2.7.5:

(object) ar('html')->menu( $tagName = 'ul', ... )

(string) $tagName The tag name to use for the menu list element. Defaults to <ul>
(array) $attributes A list of attributes for the menu element. Optional.
(mixed) $childNodes A list of childnodes as a string or an ar_htmlNodes object. Optional.

This method returns a new ar_html_menuElement object. This class extends the ar_htmlElement class, so you can access its content using the html/xml dom methods. In Ariadne > 2.7.5 this method works exactly like the ar\html::el() method. To fill the menu with menu items, use the ar\html\menuElement::fill() method.

el

Available in Ariadne > 2.7.3, replaces ar_html::tag().

(object) ar('html')->el( $tagName, ... )
(object) ar('html')->element( $tagName, ... )

(string) $tagName The name of the HTML tag.
(array) $attributes A list of attributes.
(mixed) $childNodes The child nodes as a string or as an ar_htmlNodes object, as generated by ar('html')->nodes.

You can add as many attributes or childNodes as you want after $tagName. All attributes will be merged into one list. The method returns an ar_htmlElement object. This class only differs from the ar_xmlElement class in the way it converts itself to a string.

parse

(object) ar('html')->parse( $html )

(string) $html The HTML string to parse.

This method parses a string of HTML and returns an HTML nodes list. This allows you to simply manipulate existing HTML. e.g.:

<pinp>
 $dom = ar('html')->parse(
ar('http')->get( 'http://www.ariadne-cms.org/' )
);
  echo $dom->getElementById('menu');
</pinp>

This will echo the main menu of the ariadne-cms.org website. Or you can grab all heading2 nodes and list their text contents:

<pinp>
$heading2list = $dom->getElementsByTagName('h2')->nodeValue;
</pinp>

This gives you an array of strings with all the H2 titles. And finally you can also simply walk to the exact node you want and grab its contents, or manipulate it in some other way:

<pinp>
$heading1node = $dom->html->body->div[0]->h1;
</pinp>

table

(object) ar('html')->table( $data, $attributes = null )

(mixed) $data An array of data, one or two levels, or a content string.
(array) $attributes An array attributes for the table tag.

This method returns a new ar_html_table object. This class has a number of methods to quickly generate an accessible html table.

tag

Deprecated in Ariadne > 2.7.3, use ar_html::el() instead.

(object) ar('html')->tag( $tagName, ... )

(string) $tagName The name of the HTML tag.
(array) $attributes A list of attributes.
(string) $childNodes The child nodes as a string or as an ar_htmlNodes object, as generated by ar('html')->nodes.

You can add as many attributes or childNodes as you want after $tagName. All attributes will be merged into one list. The method returns an ar_htmlElement object. This class only differs from the ar_xmlElement class in the way it converts itself to a string.