Development Core Html

From Cloudrexx Development Wiki
Jump to: navigation, search


The Html class contains (mostly static) methods and constants which are useful for the generation of HTML code. The intention of this class is to generate consistent and error-free code.

Hint: There are hangovers in the code which e.g. are from customer projects and which should not be used by Contrexx. They will be removed in a further version.


Contrexx API for \HTML Class
Contrexx API for \HTMLTag Class


The following constants should be used everytime the attribute has to be inserted dynamically.

    const ATTRIBUTE_CHECKED = ' checked="checked"';
    const ATTRIBUTE_SELECTED = ' selected="selected"';
    const ATTRIBUTE_DISABLED = ' disabled="disabled"';
    const ATTRIBUTE_READONLY = ' readonly="readonly"';
    const ATTRIBUTE_MULTIPLE = ' multiple="multiple"';

    const CSS_DISPLAY_NONE = 'display:none;';
    const CSS_DISPLAY_INLINE = 'display:inline;';
    const CSS_DISPLAY_BLOCK = 'display:block;';


Example: getInputText(): Generates HTML code for a one line text input field.

The documentation of this and all other methods are visible in the PHPDoc in the code or on the documentation page.

     * Returns HTML code for a text imput field
     * If the $id parameter is false, the id attribute is not set.
     * If it's empty (but not false), the name is used instead.
     * If the custom attributes parameter $attribute is empty, and
     * is_numeric($value) evaluates to true, the text is right aligned
     * within the input element.
     * @param   string    $name         The element name
     * @param   string    $value        The element value, defaults to the
     *                                  empty string
     * @param   string    $id           The optional element id, defaults to
     *                                  false for none
     * @param   string    $attribute    Additional optional attributes
     * @return  string                  The HTML code for the element
     * @author  Reto Kohli <>
    static function getInputText($name, $value='', $id=false, $attribute='')
            '<input type="text" name="'.$name.'"'.
            ($id === false ? '' : ' id="'.($id ? $id : $name).'"').
            ' value="'.contrexx_raw2xhtml($value).'"'.
            (preg_match('/\btabindex\b/', $attribute)
              ? '' : ' tabindex="'.++self::$index_tab.'"').
              ? " $attribute"
              : (is_numeric($value)
                  ? ' style="text-align: right;"'
                  : '')).
            " />\n";