Marc Lehmann > PApp > PApp::HTML

Download:
PApp-2.0.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 2   Source  

NAME ^

PApp::HTML - utility functions for html generation

SYNOPSIS ^

  use PApp::HTML;

DESCRIPTION ^

This module provides a host of HTML-related convenience functions, most of which output HTML elements.

Functions ^

escape_html $arg

Returns the html-escaped version of $arg (escaping characters like '<' and '&', as well as any whitespace characters other than space, cr and lf).

escape_uri $arg

Returns the uri-escaped version of $arg, escaping characters like ' ' (space) and ';' into url-escaped-form using %hex-code. This function encodes characters with code >255 as utf-8 characters.

escape_attr $arg

Returns the attribute-escaped version of $arg (it also wraps its argument into single quotes, so don't do that yourself).

errbox $error, $explanation [DEPRECATED]

Render a two-part error-box, very distinctive, very ugly, very visible!

Convenience Functions to Create XHTML Elements

The following functions are shortcuts to various often-used html tags (mostly form elements). All of them allow an initial argument attrs of type hashref which can contain attribute => value pairs. Attributes always required for the given element (e.g. "name" for form-elements) can usually be specified directly without using that hash. $value is usually the initial state/content of the input element (e.g. some text for textfield or boolean for checkbox).

tag $tagname [, \%attr ] [, $content...]

Return an XHTML element with the given tagname, optional attributes and content. img, br and input elements are handled specially (content model empty).

$ahref = alink [\%attrs,] contents, url [DEPRECATED]

Create "a link" (a href) with the given contents, pointing at the given url. It uses single quotes to delimit the url, so watch out and escape yourself!

submit [\%attrs,] $name [, $value]
submit_image [\%attrs,] $name, $img_url [, $value]

Submits a graphical submit button. $img_url must be the url to the image that is to be used.

reset_button [\%attrs,] $name
textfield [\%attrs,] $name [, $value]

Creates an input element of type text named $name. Examples:

   textfield "field1";
   textfield "field1", "some text";
   textfield { maxlength => 20 }, "field1";
textarea [\%attrs,] $name, [, $value]

Creates an input element of type textarea named $name

password_field [\%attrs,] $name [, $value]

Creates an input element of type password named $name

hidden [\%attrs,] $name [, $value]

Creates an input element of type hidden named $name

checkbox [\%attrs,] $name [, $value [, $checked]]

Creates an input element of type checkbox named $name

radio [\%attrs,] $name [, $value [, $checked]]

Creates an input element of type radiobutton named $name

filefield [\%attrs,] $name [, $value]

Creates an input element of type file named $name

selectbox [\%attrs,] $name, [$selected, [, $key => $text...]]

Creates an input element of type select(box) named $name. $selected should be the currently selected value (or an arrayref containing all selected values). All remaining arguments are treated as name (displayed) => value (submitted) pairs.

javascript $code

Returns a script element containing correctly quoted code inside a comment as recommended in HTML 4. Every occurence of -- will be replaced by -\- to avoid generating illegal syntax (for XHTML compatibility). Yes, this means that the decrement operator is certainly out. One would expect browsers to properly support entities inside script tags, but of course they don't, ruling better solutions totally out.

If you use a stylesheet, consider something like this for your head-section:

   <script type="text/javascript" language="javascript1.3" defer="defer">
      <xsl:comment>
         <xsl:text>&#10;</xsl:text>
         <xsl:for-each select="descendant::script">
            <xsl:text disable-output-escaping="yes"><xsl:value-of select="text()"/></xsl:text>
         </xsl:for-each>
         <xsl:text>//</xsl:text>
      </xsl:comment>
   </script>
mailto_url $mailaddr, key => value, ...

Create a mailto url with the specified headers (see RFC 2368). All values will be properly escaped for you. Example:

 mailto_url "schmorp@schmorp.de",
            subject => "Mail from me",
            body => "hello, world!";

SEE ALSO ^

PApp, PApp::XML.

AUTHOR ^

 Marc Lehmann <schmorp@schmorp.de>
 http://home.schmorp.de/
syntax highlighting: