pieforms-commit Mailing List for Pieforms (Page 6)
Status: Alpha
Brought to you by:
oracleshinoda
You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(73) |
Dec
(83) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(16) |
Feb
(19) |
Mar
(12) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(14) |
Sep
(2) |
Oct
(1) |
Nov
(2) |
Dec
(45) |
2008 |
Jan
(20) |
Feb
(3) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
(3) |
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
(1) |
2009 |
Jan
(2) |
Feb
(2) |
Mar
|
Apr
(2) |
May
(1) |
Jun
(5) |
Jul
(1) |
Aug
(2) |
Sep
(1) |
Oct
|
Nov
(7) |
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <ora...@us...> - 2007-03-18 12:37:36
|
Revision: 196 http://svn.sourceforge.net/pieforms/?rev=196&view=rev Author: oracleshinoda Date: 2007-03-18 01:59:16 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Added script to build documentation Added Paths: ----------- pieforms-php5/branches/0.2.0/doc/makedocs.py Added: pieforms-php5/branches/0.2.0/doc/makedocs.py =================================================================== --- pieforms-php5/branches/0.2.0/doc/makedocs.py (rev 0) +++ pieforms-php5/branches/0.2.0/doc/makedocs.py 2007-03-18 08:59:16 UTC (rev 196) @@ -0,0 +1,111 @@ +#!/usr/bin/env python +# +# @todo: script that uses docutils to build documentation +# +# This script should somehow do magical geshi processing too... +# See the MochiKit make_docs.py script +# +import os +import subprocess +try: + from pg_resources import require + require("docutils>0.3.9") +except ImportError: + pass +from docutils import nodes, utils +from docutils.core import publish_parts +from docutils.parsers import rst +from docutils.parsers.rst import roles +from docutils.parsers.rst import directives +from docutils.parsers.rst.directives import body + +TEMPLATE = u"""%(html_prolog)s +<html xmlns=http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +%(html_head)s +<link rel="stylesheet" type="text/css" href="%(css_path)s" /> +</head> +<body> +%(html_body)s +<div id="footer">Pieforms by <a href="http://nigel.mcnie.name/">Nigel McNie</a> and <a href="http://pieforms.sourceforge.net/about#authors">others</a>, +© 2006 Catalyst IT Ltd. Pieforms is released under the <a href="http://gnu.org/licences/gpl.html">GNU GPL</a></div> +</body> +</html> +""" + +def role_breadcrumbs(role, rawtext, text, lineno, inliner, options=None, content=[]): + if options is None: + options = {} + + links = [] + parts = text.split(' > ') + dirs = '../' * len(parts) + for title in parts: + dirs = dirs[:-3] + links.append("<a href=\"" + dirs + "\">" + title + "</a>") + + html = '<div id="breadcrumbs"><a href="http://pieforms.sourceforge.net/">Pieforms Home</a> » ' + ' » '.join(links) + '</div>' + + return [nodes.raw('', html, format='html')], [] + +roles.register_canonical_role('breadcrumbs', role_breadcrumbs) + +def highlighter(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine): + # block_text contains the full text + language = arguments[0] + program = [r"php", "highlighter.php", block_text, language] + + call = subprocess.Popen(program, 0, None, None, subprocess.PIPE) + result = call.stdout.read() + return [nodes.raw('', result, format='html')] + +highlighter.content = True +highlighter.arguments = (1, 0, False) + +directives.register_directive('highlight', highlighter) + +def main(): + basepath = 'rst' + destpath = 'html' + for root, dirs, files in os.walk(basepath): + if '.svn' in dirs: + dirs.remove('.svn') + + # Work out the directory the file is to be placed in. Remove the + # trailing slash also, since it interferes with CSS path + # generation + destdirname = os.path.join(destpath, root[len(basepath)+1:]) + if destdirname.endswith('/'): + destdirname = destdirname[:-1] + + if not os.path.exists(destdirname): + os.mkdir(destdirname) + csspath = '../' * (len(destdirname.split('/')) - 1) + 'style.css' + + for fn in files: + basefn, ext = os.path.splitext(fn) + if ext == '.rst': + srcfn = os.path.join(root, fn) + dest = os.path.join(destdirname, basefn + '.html') + # caching here + print srcfn + parts = publish_parts( + source_path=srcfn, + source=file(srcfn, 'rb').read().decode('utf8'), + destination_path=dest, + writer_name='html', + settings_overrides=dict( + embed_stylesheet=False + ) + ) + parts['html_head'] = parts['html_head'] % ('utf-8') + parts['html_prolog'] = parts['html_prolog'] % ('utf-8') + parts['css_path'] = csspath + doc = (TEMPLATE % parts).encode('utf8') + out = file(dest, 'wb') + out.write(doc) + out.close() + + +if __name__ == '__main__': + main() Property changes on: pieforms-php5/branches/0.2.0/doc/makedocs.py ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-03-18 12:36:11
|
Revision: 199 http://svn.sourceforge.net/pieforms/?rev=199&view=rev Author: oracleshinoda Date: 2007-03-18 02:05:07 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Added HTML documentation Added Paths: ----------- pieforms-php5/branches/0.2.0/doc/html/ pieforms-php5/branches/0.2.0/doc/html/html4css1.css pieforms-php5/branches/0.2.0/doc/html/index.html pieforms-php5/branches/0.2.0/doc/html/style.css pieforms-php5/branches/0.2.0/doc/html/user/ pieforms-php5/branches/0.2.0/doc/html/user/concepts.html pieforms-php5/branches/0.2.0/doc/html/user/configuration.html pieforms-php5/branches/0.2.0/doc/html/user/elements.html pieforms-php5/branches/0.2.0/doc/html/user/examples.html pieforms-php5/branches/0.2.0/doc/html/user/features.html pieforms-php5/branches/0.2.0/doc/html/user/usage.html Added: pieforms-php5/branches/0.2.0/doc/html/html4css1.css =================================================================== --- pieforms-php5/branches/0.2.0/doc/html/html4css1.css (rev 0) +++ pieforms-php5/branches/0.2.0/doc/html/html4css1.css 2007-03-18 09:05:07 UTC (rev 199) @@ -0,0 +1,279 @@ +/* +:Author: David Goodger +:Contact: go...@us... +:Date: $Date: 2005-12-18 01:56:14 +0100 (Sun, 18 Dec 2005) $ +:Revision: $Revision: 4224 $ +:Copyright: This stylesheet has been placed in the public domain. + +Default cascading style sheet for the HTML output of Docutils. + +See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to +customize this style sheet. +*/ + +/* used to remove borders from tables and images */ +.borderless, table.borderless td, table.borderless th { + border: 0 } + +table.borderless td, table.borderless th { + /* Override padding for "table.docutils td" with "! important". + The right padding separates the table cells. */ + padding: 0 0.5em 0 0 ! important } + +.first { + /* Override more specific margin styles with "! important". */ + margin-top: 0 ! important } + +.last, .with-subtitle { + margin-bottom: 0 ! important } + +.hidden { + display: none } + +a.toc-backref { + text-decoration: none ; + color: black } + +blockquote.epigraph { + margin: 2em 5em ; } + +dl.docutils dd { + margin-bottom: 0.5em } + +/* Uncomment (and remove this text!) to get bold-faced definition list terms +dl.docutils dt { + font-weight: bold } +*/ + +div.abstract { + margin: 2em 5em } + +div.abstract p.topic-title { + font-weight: bold ; + text-align: center } + +div.admonition, div.attention, div.caution, div.danger, div.error, +div.hint, div.important, div.note, div.tip, div.warning { + margin: 2em ; + border: medium outset ; + padding: 1em } + +div.admonition p.admonition-title, div.hint p.admonition-title, +div.important p.admonition-title, div.note p.admonition-title, +div.tip p.admonition-title { + font-weight: bold ; + font-family: sans-serif } + +div.attention p.admonition-title, div.caution p.admonition-title, +div.danger p.admonition-title, div.error p.admonition-title, +div.warning p.admonition-title { + color: red ; + font-weight: bold ; + font-family: sans-serif } + +/* Uncomment (and remove this text!) to get reduced vertical space in + compound paragraphs. +div.compound .compound-first, div.compound .compound-middle { + margin-bottom: 0.5em } + +div.compound .compound-last, div.compound .compound-middle { + margin-top: 0.5em } +*/ + +div.dedication { + margin: 2em 5em ; + text-align: center ; + font-style: italic } + +div.dedication p.topic-title { + font-weight: bold ; + font-style: normal } + +div.figure { + margin-left: 2em ; + margin-right: 2em } + +div.footer, div.header { + clear: both; + font-size: smaller } + +div.line-block { + display: block ; + margin-top: 1em ; + margin-bottom: 1em } + +div.line-block div.line-block { + margin-top: 0 ; + margin-bottom: 0 ; + margin-left: 1.5em } + +div.sidebar { + margin-left: 1em ; + border: medium outset ; + padding: 1em ; + background-color: #ffffee ; + width: 40% ; + float: right ; + clear: right } + +div.sidebar p.rubric { + font-family: sans-serif ; + font-size: medium } + +div.system-messages { + margin: 5em } + +div.system-messages h1 { + color: red } + +div.system-message { + border: medium outset ; + padding: 1em } + +div.system-message p.system-message-title { + color: red ; + font-weight: bold } + +div.topic { + margin: 2em } + +h1.section-subtitle, h2.section-subtitle, h3.section-subtitle, +h4.section-subtitle, h5.section-subtitle, h6.section-subtitle { + margin-top: 0.4em } + +h1.title { + text-align: center } + +h2.subtitle { + text-align: center } + +hr.docutils { + width: 75% } + +img.align-left { + clear: left } + +img.align-right { + clear: right } + +ol.simple, ul.simple { + margin-bottom: 1em } + +ol.arabic { + list-style: decimal } + +ol.loweralpha { + list-style: lower-alpha } + +ol.upperalpha { + list-style: upper-alpha } + +ol.lowerroman { + list-style: lower-roman } + +ol.upperroman { + list-style: upper-roman } + +p.attribution { + text-align: right ; + margin-left: 50% } + +p.caption { + font-style: italic } + +p.credits { + font-style: italic ; + font-size: smaller } + +p.label { + white-space: nowrap } + +p.rubric { + font-weight: bold ; + font-size: larger ; + color: maroon ; + text-align: center } + +p.sidebar-title { + font-family: sans-serif ; + font-weight: bold ; + font-size: larger } + +p.sidebar-subtitle { + font-family: sans-serif ; + font-weight: bold } + +p.topic-title { + font-weight: bold } + +pre.address { + margin-bottom: 0 ; + margin-top: 0 ; + font-family: serif ; + font-size: 100% } + +pre.literal-block, pre.doctest-block { + margin-left: 2em ; + margin-right: 2em ; + background-color: #eeeeee } + +span.classifier { + font-family: sans-serif ; + font-style: oblique } + +span.classifier-delimiter { + font-family: sans-serif ; + font-weight: bold } + +span.interpreted { + font-family: sans-serif } + +span.option { + white-space: nowrap } + +span.pre { + white-space: pre } + +span.problematic { + color: red } + +span.section-subtitle { + /* font-size relative to parent (h1..h6 element) */ + font-size: 80% } + +table.citation { + border-left: solid 1px gray; + margin-left: 1px } + +table.docinfo { + margin: 2em 4em } + +table.docutils { + margin-top: 0.5em ; + margin-bottom: 0.5em } + +table.footnote { + border-left: solid 1px black; + margin-left: 1px } + +table.docutils td, table.docutils th, +table.docinfo td, table.docinfo th { + padding-left: 0.5em ; + padding-right: 0.5em ; + vertical-align: top } + +table.docutils th.field-name, table.docinfo th.docinfo-name { + font-weight: bold ; + text-align: left ; + white-space: nowrap ; + padding-left: 0 } + +h1 tt.docutils, h2 tt.docutils, h3 tt.docutils, +h4 tt.docutils, h5 tt.docutils, h6 tt.docutils { + font-size: 100% } + +tt.docutils { + background-color: #eeeeee } + +ul.auto-toc { + list-style-type: none } Added: pieforms-php5/branches/0.2.0/doc/html/index.html =================================================================== --- pieforms-php5/branches/0.2.0/doc/html/index.html (rev 0) +++ pieforms-php5/branches/0.2.0/doc/html/index.html 2007-03-18 09:05:07 UTC (rev 199) @@ -0,0 +1,111 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns=http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" /> +<title>Pieforms: Advanced web forms made easy</title> + +<link rel="stylesheet" type="text/css" href="style.css" /> +</head> +<body> +<div class="document" id="pieforms-advanced-web-forms-made-easy"> +<h1 class="title"><a class="reference" href="http://pieforms.sourceforge.net/">Pieforms</a>: Advanced web forms made easy</h1> +<p><div id="breadcrumbs"><a href="http://pieforms.sourceforge.net/">Pieforms Home</a> » <a href="">Documentation Home</a></div></p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Author:</th><td class="field-body">Nigel McNie</td> +</tr> +<tr class="field"><th class="field-name">Contact:</th><td class="field-body"><a class="reference" href="mailto:nigel@catalyst.net.nz">nigel@catalyst.net.nz</a></td> +</tr> +<tr class="field"><th class="field-name">Copyright:</th><td class="field-body">This document has been placed in the public domain</td> +</tr> +</tbody> +</table> +<p>The latest copy of the Pieforms documentation may be obtained from SVN:</p> +<blockquote> +<tt class="docutils literal"><span class="pre">svn</span> <span class="pre">co</span> <span class="pre">https://pieforms.svn.sourceforge.net/svnroot/pieforms/pieforms-php5/trunk</span> <span class="pre">pieforms</span></tt></blockquote> +<div class="contents topic"> +<p class="topic-title first"><a id="contents" name="contents">Contents</a></p> +<ul class="simple"> +<li><a class="reference" href="#general-documentation" id="id1" name="id1">General Documentation</a></li> +<li><a class="reference" href="#user-user-documentation" id="id2" name="id2"><tt class="docutils literal"><span class="pre">user/</span></tt>: User Documentation</a></li> +<li><a class="reference" href="#ref-reference-material" id="id3" name="id3"><tt class="docutils literal"><span class="pre">ref/</span></tt>: Reference Material</a></li> +<li><a class="reference" href="#howto-miscellaneous-articles" id="id4" name="id4"><tt class="docutils literal"><span class="pre">howto/</span></tt>: Miscellaneous Articles</a></li> +<li><a class="reference" href="#dev-core-development-information" id="id5" name="id5"><tt class="docutils literal"><span class="pre">dev/</span></tt>: Core Development Information</a></li> +</ul> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id1" id="general-documentation" name="general-documentation">General Documentation</a></h1> +<p>These files may be of interest to any Pieforms user.</p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name"><a class="reference" href="../../README">README</a>:</th><td class="field-body">The project overview, requirements, and licensing details</td> +</tr> +<tr class="field"><th class="field-name"><a class="reference" href="../../COPYING">COPYING</a>:</th><td class="field-body">Pieforms is licensed under the <a class="reference" href="http://gnu.org/licenses/gpl.html">GNU GPL</a>, this file contains a full +copy of the license</td> +</tr> +</tbody> +</table> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id2" id="user-user-documentation" name="user-user-documentation"><span id="user"></span><tt class="docutils literal"><span class="pre">user/</span></tt>: User Documentation</a></h1> +<p>These files contain documentation about how to use Pieforms. They will be of +interest to almost any Pieforms user.</p> +<ul class="simple"> +<li><a class="reference" href="user/concepts.html">Pieforms Concepts and Terms</a> - basic Pieforms +concepts. <strong>Read this first!</strong></li> +<li><a class="reference" href="user/features.html">Pieforms Feature List</a> - list of major Pieforms +features</li> +<li><a class="reference" href="user/configuration.html">Pieforms Configuration</a> - instructions on +installation and basic configuration of Pieforms</li> +<li><a class="reference" href="user/usage.html">Basic Usage</a> - A step by step guide to writing your +first Pieform</li> +<li><a class="reference" href="user/examples.html">Examples of Pieforms</a> - examples that show +Pieforms usage, and may give you good ideas</li> +<li><a class="reference" href="user/elements.html">Elements</a> - General information about elements +including a list of elements that come with Pieforms.</li> +<li><a class="reference" href="user/renderers.html">Renderers</a></li> +<li><a class="reference" href="user/rules.html">Rules</a></li> +<li><a class="reference" href="user/i18n.html">i18n</a></li> +</ul> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id3" id="ref-reference-material" name="ref-reference-material"><tt class="docutils literal"><span class="pre">ref/</span></tt>: Reference Material</a></h1> +<p>These files contain developer specifications and reference notes that will be +of interest to anyone who wishes to write plugins for Pieforms, or re-implement +it in another language.</p> +<ul class="simple"> +<li><a class="reference" href="ref/api/index.html">Pieforms frontend API documentation (in phpdoc form)</a></li> +<li><a class="reference" href="ref/elements.html">Element API</a></li> +<li><a class="reference" href="ref/renderers.html">Renderer API</a></li> +<li><a class="reference" href="ref/rules.html">Rule API</a></li> +<li><a class="reference" href="ref/i18n.html">i18n API</a></li> +</ul> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id4" id="howto-miscellaneous-articles" name="howto-miscellaneous-articles"><tt class="docutils literal"><span class="pre">howto/</span></tt>: Miscellaneous Articles</a></h1> +<p>These files contain various documentation about the use of Pieforms in many +situations.</p> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id5" id="dev-core-development-information" name="dev-core-development-information"><tt class="docutils literal"><span class="pre">dev/</span></tt>: Core Development Information</a></h1> +<p>These files contain information for Pieforms hackers, administrators and others +involved with the Pieforms source.</p> +<ul class="simple"> +<li><a class="reference" href="dev/coding.html">Pieforms Coding Standards</a></li> +<li><a class="reference" href="dev/todo.html">Pieforms TODO List</a></li> +</ul> +<p><div id="breadcrumbs"><a href="http://pieforms.sourceforge.net/">Pieforms Home</a> » <a href="">Documentation Home</a></div></p> +</div> +</div> + +<div id="footer">Pieforms by <a href="http://nigel.mcnie.name/">Nigel McNie</a> and <a href="http://pieforms.sourceforge.net/about#authors">others</a>, +© 2006 Catalyst IT Ltd. Pieforms is released under the <a href="http://gnu.org/licences/gpl.html">GNU GPL</a></div> +</body> +</html> Added: pieforms-php5/branches/0.2.0/doc/html/style.css =================================================================== --- pieforms-php5/branches/0.2.0/doc/html/style.css (rev 0) +++ pieforms-php5/branches/0.2.0/doc/html/style.css 2007-03-18 09:05:07 UTC (rev 199) @@ -0,0 +1,88 @@ +/* + :Author: Nigel McNie + :Contact: ni...@ca... + :Copyright: This stylesheet has been placed in the public domain. + + Stylesheet for use with Docutils. + + TODO: + - style a bit more like the website (green header, margins) + - header should have the links like the rest of the site to various places + - some kind of breadcrumbs + */ + +@import url(html4css1.css); + +html, body { + font-family: Verdana, sans-serif; + font-size: 0.9em; + margin: 0; + padding: 0; +} +body { + width: 90%; + margin: 0 auto; +} + +h1, h2, h3, h4, h5, h6 { + font-family: "Trebuchet MS", sans-serif; +} +a[href!=""] { + color: blue; + text-decoration: underline; +} +a:visited { + color: #551a8b; +} +a:active { + color: blue; +} +h1.title { + background-color: #cfc; + border-bottom: 1px solid #393; + color: #6a6; + padding: 0.7em; + margin: 0 -5.5%; +} +h1.title a { + color: #6a6; +} +h2, h3 { + margin: .5em 0 .25em; + color: #363; +} +hr { + height: 0; + border: solid #696; + border-width: 0 0 1px 0; +} +ul { + margin: 0 2.5em; + padding: 0 0 0 .2em; +} +li { + margin: 0; + padding: 0 0 0 .5em; +} +pre a { + text-decoration: none; +} + +#breadcrumbs { + padding: 0 0.75em; + margin: -.3em 0 0 -.5em; + font-size: smaller; + color: #393; +} +#breadcrumbs a { + color: #6a6; +} +#footer { + background-color: #f0f0f0; + border-top: 1px solid #c0c0c0; + color: #808080; + font-size: smaller; + padding: 0.25em 0 1em; + text-align: center; + margin: 1em -5.5% 0; +} Added: pieforms-php5/branches/0.2.0/doc/html/user/concepts.html =================================================================== --- pieforms-php5/branches/0.2.0/doc/html/user/concepts.html (rev 0) +++ pieforms-php5/branches/0.2.0/doc/html/user/concepts.html 2007-03-18 09:05:07 UTC (rev 199) @@ -0,0 +1,302 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns=http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" /> +<title>Pieforms Concepts and Terms</title> + +<link rel="stylesheet" type="text/css" href="../style.css" /> +</head> +<body> +<div class="document" id="pieforms-concepts-and-terms"> +<h1 class="title">Pieforms Concepts and Terms</h1> +<p><div id="breadcrumbs"><a href="http://pieforms.sourceforge.net/">Pieforms Home</a> » <a href="../">Documentation Home</a> » <a href="">Pieform Concepts and Terms</a></div></p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Author:</th><td class="field-body">Nigel McNie</td> +</tr> +<tr class="field"><th class="field-name">Contact:</th><td class="field-body"><a class="reference" href="mailto:nigel@catalyst.net.nz">nigel@catalyst.net.nz</a></td> +</tr> +<tr class="field"><th class="field-name">Copyright:</th><td class="field-body">This document has been placed in the public domain</td> +</tr> +</tbody> +</table> +<div class="contents topic"> +<p class="topic-title first"><a id="contents" name="contents">Contents</a></p> +<ul class="simple"> +<li><a class="reference" href="#background" id="id1" name="id1">Background</a></li> +<li><a class="reference" href="#concepts" id="id2" name="id2">Concepts</a><ul> +<li><a class="reference" href="#the-form-definition-hash" id="id3" name="id3">The form definition hash</a></li> +<li><a class="reference" href="#the-pieform-function-call" id="id4" name="id4">The <tt class="docutils literal"><span class="pre">pieform(...)</span></tt> function call</a></li> +<li><a class="reference" href="#the-testform-validate-function" id="id5" name="id5">The <tt class="docutils literal"><span class="pre">testform_validate</span></tt> function</a></li> +<li><a class="reference" href="#the-testform-submit-function" id="id6" name="id6">The <tt class="docutils literal"><span class="pre">testform_submit</span></tt> function</a></li> +</ul> +</li> +<li><a class="reference" href="#form-api-terms" id="id7" name="id7">Form API Terms</a><ul> +<li><a class="reference" href="#elements" id="id8" name="id8">Elements</a></li> +<li><a class="reference" href="#rules" id="id9" name="id9">Rules</a></li> +<li><a class="reference" href="#renderers" id="id10" name="id10">Renderers</a></li> +</ul> +</li> +<li><a class="reference" href="#how-they-fit-together" id="id11" name="id11">How They Fit Together</a></li> +<li><a class="reference" href="#other-features-of-pieforms" id="id12" name="id12">Other Features of Pieforms</a></li> +</ul> +</div> +<p>Pieforms is a development of the <a class="reference" href="http://mahara.org/">Mahara</a> project, that was later split out into +its own project on <a class="reference" href="http://pieforms.sourceforge.net/">sourceforge</a>. It provides a unified way to create, validate +and process forms all with a common look and feel, with support for pluggable +elements, renderers and validation rules.</p> +<p>What does that all mean? That's what this document is for - to describe the +overall concepts and ideas behind Pieforms.</p> +<div class="section"> +<h1><a class="toc-backref" href="#id1" id="background" name="background">Background</a></h1> +<div class="note"> +<p class="first admonition-title">Note</p> +<p class="last">You can skip this section if you don't care for history lessons :)</p> +</div> +<p>In late 2006, the areformentioned Mahara project was in full swing. One of the +technical requirements identified was for a common API for displaying and +processing forms. Nigel was tasked with this job as he had claimed some +familiarity with various PHP form APIs. The three that were given some +consideration were <a class="reference" href="http://drupal.org/">Drupal's</a> forms API, PEAR's <a class="reference" href="http://pear.php.net/package/HTML_QuickForm">QuickForm</a> and Moodle's <a class="reference" href="http://moodle.cvs.sourceforge.net/moodle/moodle/lib/form/">form +API</a>, which was under development at the time.</p> +<p>Of the three, QuickForm was discarded nearly straight away, due to the large +amount of work to produce any one form, and indifferent experiences by members +of the development team in using it before. Moodle's API was briefly considered +but then dropped, as it appeared to have a similar, "heavy" API and was under +development at the time. This left Drupal's form API as the main contender, and +it probably would have won if it could have been pulled out of Drupal +successfully. Unfortunately, all efforts to extract it so that it would sit on +its own failed - it was too tightly bound to Drupal itself.</p> +<p>This resulted in the undersirable situation of one form API required vs. none +available. So in an orgy of weekend coding (and over the next few days at +work), Nigel cobbled together a form API with blackjack and hookers. And +amazingly, it worked pretty well. The best part was that writing forms was +insanely quick (including full validation). And soon after, Richard Mansfield +added 'AJAX form' support - forms that submitted very quickly because they were +posted and got their results asynchronously.</p> +<p>About the same time, Nigel made the elements, renderers and rules fully +pluggable by anyone who wanted to write a new one. It was then that he realised +that this little subproject had turned into a cool implementation of a form +API, that was worth splitting out into its own project. And thus, Pieforms was +born. The name was chosen as a tribute to a leaving team member, whose nick on +IRC was 'pie' :)</p> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id2" id="concepts" name="concepts">Concepts</a></h1> +<p>So, what is it that made Pieforms so easy to use and quick to build forms with? +It is because from the outset the library was designed to build forms with as +little work by the user as possible, instead of following a strict 'OO' +approach. As a result, the three or four things you need for a form are:</p> +<ul class="simple"> +<li>A hash containing the form definition. Basically, this is a big array +describing the overall form properties, and the elements in the form</li> +<li>An optional callback function that can be used to validate a form submission +(which is practice is not required very often as the inbuilt rules handle most +validation)</li> +<li>A callback function that handles the submission of the form. This function +can do anything with the submitted values, in the knowledge that the values are +fully validated.</li> +<li>A call to the <tt class="docutils literal"><span class="pre">pieform()</span></tt> function, passing the form definition, which +manages the entire form building, validating, submitting and displaying +process.</li> +</ul> +<p>Here is an example of a simple form</p> +<pre style="background-color:#ffc;border:1px solid #cc9;"><a href="http://www.php.net/require_once"><span style="color:#a1a100;" title="php/php/keyword">require_once</span></a><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">pieform.php</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">;</span> + +<a href="http://www.php.net/echo"><span style="color:#a1a100;" title="php/php/keyword">echo</span></a> <span style="color:#600;font-weight:bold;" title="php/php/functioncall">pieform</span><span style="color:#008000;" title="php/php/symbol">(</span><a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">name</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">testform</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">method</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">post</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">action</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">elements</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">details</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">type</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">fieldset</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">legend</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">Your Details</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">elements</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">fullname</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">type</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">text</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">title</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">Full name</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">description</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">Please enter your full name</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">rules</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">required</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="font-weight:bold;color:#000;" title="php/php/constant">true</span> + <span style="color:#008000;" title="php/php/symbol">)</span> + <span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">dob</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">type</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">date</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">title</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">Date of Birth</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">description</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">Your date of birth</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">defaultvalue</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/strtotime"><span style="color:#006;" title="php/php/function">strtotime</span></a><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">1st of January, 1985</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">rules</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">required</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="font-weight:bold;color:#000;" title="php/php/constant">true</span> + <span style="color:#008000;" title="php/php/symbol">)</span> + <span style="color:#008000;" title="php/php/symbol">)</span> + <span style="color:#008000;" title="php/php/symbol">)</span> + <span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">,</span> + + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">submit</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <a href="http://www.php.net/array"><span style="color:#a1a100;" title="php/php/keyword">array</span></a><span style="color:#008000;" title="php/php/symbol">(</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">type</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">submit</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> + <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">value</span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">=</span><span style="color:#008000;" title="php/php/symbol">></span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">Submit</span><span style="color:#f00;" title="php/php/single_string/end">'</span> + <span style="color:#008000;" title="php/php/symbol">)</span> + <span style="color:#008000;" title="php/php/symbol">)</span> +<span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">;</span> + +<span style="color:#a1a100;" title="php/php/keyword">function</span> <span style="color:#600;" title="php/php/functionname">testform_validate</span><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#000;" title="php/php">Pieform</span> <span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">form</span><span style="color:#008000;" title="php/php/symbol">,</span> <span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">values</span><span style="color:#008000;" title="php/php/symbol">)</span> <span style="color:#008000;" title="php/php/symbol">{</span> + <span style="color:#a1a100;" title="php/php/keyword">if</span> <span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#008000;" title="php/php/symbol">!</span><span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">form</span><span style="color:#008000;" title="php/php/symbol">-></span><span style="color:#933;" title="php/php/oodynamic">get_error</span><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">dob</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">)</span> <span style="color:#008000;" title="php/php/symbol">&</span><span style="color:#008000;" title="php/php/symbol">&</span> <span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">values</span><span style="color:#008000;" title="php/php/symbol">[</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">dob</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">]</span> <span style="color:#008000;" title="php/php/symbol"><</span> <a href="http://www.php.net/strtotime"><span style="color:#006;" title="php/php/function">strtotime</span></a><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">1st of January, 1950</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">)</span> <span style="color:#008000;" title="php/php/symbol">{</span> + <span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">form</span><span style="color:#008000;" title="php/php/symbol">-></span><span style="color:#933;" title="php/php/oodynamic">set_error</span><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">dob</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">,</span> <span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">I will give you another chance to lie about your age, OK? :)</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">;</span> + <span style="color:#008000;" title="php/php/symbol">}</span> +<span style="color:#008000;" title="php/php/symbol">}</span> + +<span style="color:#a1a100;" title="php/php/keyword">function</span> <span style="color:#600;" title="php/php/functionname">testform_submit</span><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#000;" title="php/php">Pieform</span> <span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">form</span><span style="color:#008000;" title="php/php/symbol">,</span> <span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">values</span><span style="color:#008000;" title="php/php/symbol">)</span> <span style="color:#008000;" title="php/php/symbol">{</span> + <a href="http://www.php.net/print_r"><span style="color:#006;" title="php/php/function">print_r</span></a><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">values</span><span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">;</span> + <a href="http://www.php.net/exit"><span style="color:#a1a100;" title="php/php/keyword">exit</span></a><span style="color:#008000;" title="php/php/symbol">;</span> +<span style="color:#008000;" title="php/php/symbol">}</span></pre><p>Here is a description of each part.</p> +<div class="section"> +<h2><a class="toc-backref" href="#id3" id="the-form-definition-hash" name="the-form-definition-hash">The form definition hash</a></h2> +<p>This array contains the definition of the form. In this example the form is +hard coded, and that would be what you would do most of the time, but there's +nothing to stop it from being generated dynamically. The array specifies some +metadata for the whole form, like its name, method and action target, and then +a list of elements that are on the form. Evary form must have a name, this name +is used to call the callback functions.</p> +<p>More information about the form array is available on a <a class="reference" href="usage.html">separate page</a>.</p> +</div> +<div class="section"> +<h2><a class="toc-backref" href="#id4" id="the-pieform-function-call" name="the-pieform-function-call">The <tt class="docutils literal"><span class="pre">pieform(...)</span></tt> function call</a></h2> +<p>This call builds the form, validates and submits the form if it has been +submitted, and returns the HTML for the form. So in the example above the form +is simply <tt class="docutils literal"><span class="pre">echo</span></tt>'d to the browser, but it could easily be put into a <a class="reference" href="http://smarty.php.net/">Smarty</a> template variable or manipulated any way required.</p> +</div> +<div class="section"> +<h2><a class="toc-backref" href="#id5" id="the-testform-validate-function" name="the-testform-validate-function">The <tt class="docutils literal"><span class="pre">testform_validate</span></tt> function</a></h2> +<p>This function is named after the form name, with <tt class="docutils literal"><span class="pre">_validate</span></tt> on the end. It +takes the Pieform object and an array of the submitted values, and can perform +whatever checks are required that cannot be otherwise handled by the inbuilt +form rules. In this case, rather than being a serious rule, a check is made to +give the older viewers a chance to not be so old :). Notice how it uses the +<tt class="docutils literal"><span class="pre">$form</span></tt> object to check for an error beforehand (which might have happened if +the "required" rule was violated, although generally that is quite hard to +violate with the "date" element), and uses it again to set an error on the +form.</p> +<p>This function is optional, as most of the time you will be able to perform all +the validation you require using rules. Notice in the array in the example how +each element had a 'required' rule. If that was all the validation you +required, you would not need the validate function. There are other rules +available, and it's easy to write your own.</p> +</div> +<div class="section"> +<h2><a class="toc-backref" href="#id6" id="the-testform-submit-function" name="the-testform-submit-function">The <tt class="docutils literal"><span class="pre">testform_submit</span></tt> function</a></h2> +<p>This function is named after the form name, with <tt class="docutils literal"><span class="pre">_submit</span></tt> on the end. It +takes an array of the submitted values that have already been validated +successfully according to the validation rules set on the form. From here you +can do almost anything, but the last thing that you should do is either:</p> +<ul class="simple"> +<li>Redirect the user to another page (perhaps back to this page if you wish to +always display the form to the user), if the form is a standard form</li> +<li>Reply with <tt class="docutils literal"><span class="pre">$form->json_reply(PIEFORM_OK,</span> <span class="pre">'optional</span> <span class="pre">message')</span></tt> if the form +is a JS form</li> +</ul> +<p>Because you will probably be writing a few forms, you should probably write a +wrapper for redirecting the user to another page, to save you time and effort +later. Something like this:</p> +<pre style="background-color:#ffc;border:1px solid #cc9;"><span style="color:#a1a100;" title="php/php/keyword">function</span> <span style="color:#600;" title="php/php/functionname">redirect</span><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">location</span><span style="color:#008000;" title="php/php/symbol">)</span> <span style="color:#008000;" title="php/php/symbol">{</span> + <a href="http://www.php.net/header"><span style="color:#006;" title="php/php/function">header</span></a><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">HTTP/1.1 303 See Other</span><span style="color:#f00;" title="php/php/single_string/end">'</span><span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">;</span> + <a href="http://www.php.net/header"><span style="color:#006;" title="php/php/function">header</span></a><span style="color:#008000;" title="php/php/symbol">(</span><span style="color:#f00;" title="php/php/single_string/start">'</span><span style="color:#f00;" title="php/php/single_string">Location: </span><span style="color:#f00;" title="php/php/single_string/end">'</span> <span style="color:#008000;" title="php/php/symbol">.</span> <span style="color:#33f;" title="php/php/varstart">$</span><span style="color:#33f;" title="php/php/var">location</span><span style="color:#008000;" title="php/php/symbol">)</span><span style="color:#008000;" title="php/php/symbol">;</span> + <a href="http://www.php.net/exit"><span style="color:#a1a100;" title="php/php/keyword">exit</span></a><span style="color:#008000;" title="php/php/symbol">;</span> +<span style="color:#008000;" title="php/php/symbol">}</span></pre><p>That is a very simple example, and one you will quite possibly want to extend +it further, perhaps to make specifying the location easier for example.</p> +</div> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id7" id="form-api-terms" name="form-api-terms">Form API Terms</a></h1> +<p>Pieforms has several components, a basic description of each is given here.</p> +<div class="section"> +<h2><a class="toc-backref" href="#id8" id="elements" name="elements">Elements</a></h2> +<p>Pieform <strong>elements</strong> are similar to the widgets you have in normal HTML forms, +and in fact all HTML widgets have element implementations in Pieforms. However, +Pieforms does not limit you to using just the standard HTML widgets - you can +write your own elements that have very advanced behaviour, are comprised of +multiple widgets, or do almost anything you like.</p> +<p>For example, there is a "text" element, which represents a simple HTML +<tt class="docutils literal"><span class="pre"><input</span> <span class="pre">type="text"></span></tt> widget. But there is also a "date" widget, which is +rendered as three <tt class="docutils literal"><span class="pre"><select></span></tt> widgets for year, month and day, and a +"calendar" widget which is a full-blown popup javascript calendar! The Mahara +project created a "wysiwyg" element that is a full WYSIWYG editor (a native one +will be created for Pieforms soon), and many more besides.</p> +<p>It's really easy to write your own elements, and they can be reused on any form +that needs them. <a class="reference" href="elements.html">More information about elements</a>, including +how to write your own, is available.</p> +</div> +<div class="section"> +<h2><a class="toc-backref" href="#id9" id="rules" name="rules">Rules</a></h2> +<p>Rules are used to validate elements. Given the element's value, they check if +the value matches a certain condition. There is a few simple rules implemented, +such as <em>required</em>, <em>minlength</em> and <em>maxlength</em> etc., but again like elements +they are pluggable, so many more can be written.</p> +<p>Rules may apply differently to different elements, so elements can define a +function that specifies how a rule applies to them, which allows some +flexibility in rule reuse.</p> +<p>More information on the <a class="reference" href="rules.html">rule API and writing your own rules</a> is +available.</p> +</div> +<div class="section"> +<h2><a class="toc-backref" href="#id10" id="renderers" name="renderers">Renderers</a></h2> +<p>Renderers are used to output the containers that elements are rendered inside. +For example, there is a "table" renderer which puts each element inside a table +row, and a "div" renderer that puts them inside a <tt class="docutils literal"><span class="pre"><div></span></tt>. Like elements and +rules, these are pluggable to suit your needs.</p> +<p>One thing that the Mahara project has done is added support for contextual help +for each element. The renderer will render question marks beside each form +element, which when clicked, reveal contextual help for the element. You could +add almost any extra information to each element, to assist your form output - +for example, a description, help text or raw HTML to be output at a certain +point for each element.</p> +<p>If all that was confusing, check out the <a class="reference" href="renderers.html">renderers</a> page +for more information.</p> +</div> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id11" id="how-they-fit-together" name="how-they-fit-together">How They Fit Together</a></h1> +<p>Here are some statements that might help you understand how a form is put +together using Pieforms.</p> +<p>A <strong>form</strong> is made up of <a class="reference" href="elements.html">elements</a>.</p> +<p><strong>Elements</strong> are like standard HTML widgets, except they can be more +complicated and comprised of many widgets if necessary.</p> +<p>Elements are validated by <a class="reference" href="rules.html">rules</a>.</p> +<p>Each element in a form is rendered inside some boilerplate HTML provided by a +<a class="reference" href="renderers.html">renderer</a>.</p> +<p>When forms are <strong>submitted</strong>, they are <strong>validated</strong> using the <strong>rules</strong> for +each <strong>element</strong>. If validation passes, the form <strong>submit callback</strong> is called +with the values. If validation fails, the form is redisplayed, with the +<strong>renderer</strong> drawing the error messages as returned by the <strong>rule</strong> for each +<strong>element</strong> next to it.</p> +</div> +<div class="section"> +<h1><a class="toc-backref" href="#id12" id="other-features-of-pieforms" name="other-features-of-pieforms">Other Features of Pieforms</a></h1> +<p>As well as customisable elements, renderers and rules, Pieforms has the +following features:</p> +<ul class="simple"> +<li>Forms can be sent via GET or POST</li> +<li>Forms can be sent to different pages, as long as the form definition is +available on both pages</li> +<li>Support for <strong>cancel buttons</strong> - in effect, submit buttons with no +validation applied to them</li> +<li><strong>Auto focus</strong> of fields in a form on page load, including focussing the +first element with an error if the form has failed validation</li> +<li><a class="reference" href="usage.html#jsform">JS forms</a> - forms submitted to a hidden iframe +with the result returned asynchronously, meaning the form behaves very +responsively</li> +<li>Automatic handling of <strong>tabindex</strong> for each element</li> +<li><strong>HTML 4.01 compliance</strong> (XHTML compliance will be added <a class="reference" href="../dev/todo.html#xhtml">later</a>)</li> +</ul> +<p><div id="breadcrumbs"><a href="http://pieforms.sourceforge.net/">Pieforms Home</a> » <a href="../">Documentation Home</a> » <a href="">Pieform Concepts and Terms</a></div></p> +</div> +</div> + +<div id="footer">Pieforms by <a href="http://nigel.mcnie.name/">Nigel McNie</a> and <a href="http://pieforms.sourceforge.net/about#authors">others</a>, +© 2006 Catalyst IT Ltd. Pieforms is released under the <a href="http://gnu.org/licences/gpl.html">GNU GPL</a></div> +</body> +</html> Added: pieforms-php5/branches/0.2.0/doc/html/user/configuration.html =================================================================== --- pieforms-php5/branches/0.2.0/doc/html/user/configuration.html (rev 0) +++ pieforms-php5/branches/0.2.0/doc/html/user/configuration.html 2007-03-18 09:05:07 UTC (rev 199) @@ -0,0 +1,198 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + +<html xmlns=http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<meta name="generator" content="Docutils 0.4.1: http://docutils.sourceforge.net/" /> +<title>Pieforms Configuration</title> + +<link rel="stylesheet" type="text/css" href="../style.css" /> +</head> +<body> +<div class="document" id="pieforms-configuration"> +<h1 class="title">Pieforms Configuration</h1> +<p><div id="breadcrumbs"><a href="http://pieforms.sourceforge.net/">Pieforms Home</a> » <a href="../">Documentation Home</a> » <a href="">Pieforms Configuration</a></div></p> +<table class="docutils field-list" frame="void" rules="none"> +<col class="field-name" /> +<col class="field-body" /> +<tbody valign="top"> +<tr class="field"><th class="field-name">Author:</th><td class="field-body">Nigel McNie</td> +</tr> +<tr class="field"><th class="field-name">Contact:</th><td class="field-body"><a class="reference" href="mailto:nigel@catalyst.net.nz">nigel@catalyst.net.nz</a></td> +</tr> +<tr class="field"><th class="field-name">Copyright:</th><td class="field-body">This document has been placed in the public domain</td> +</tr> +</tbody> +</table> +<div class="contents topic"> +<p class="topic-title first"><a id="contents" name="contents">Contents</a></p> +<ul class="simple"> +<li><a class="reference" href="#requirements" id="id3" name="id3">Requirements</a></li> +<li><a class="reference" href="#installation" id="id4" name="id4">Installation</a></li> +<li><a class="reference" href="#using-pieforms-on-a-page" id="id5" name="id5">Using Pieforms on a Page</a></li> +<li><a class="reference" href="#configuration" id="id6" name="id6">Configuration</a><ul> +<li><a class="reference" href="#configuring-a-default-form" id="id7" name="id7">Configuring a Default Form</a></li> +<li><a class="reference" href="#validation-for-all-forms" id="id8" name="id8">Validation for All Forms</a></li> +<li><a class="reference" href="#configuring-elements" id="id9" name="id9">Configuring elements</a></li> +</ul> +</li> +</ul> +</div> +<p>This document describes how to install and configure Pieforms for use in your +application. Once you have completed the steps in this document, all of the +features of Pieforms will be available for your use.</p> +<div class="section"> +<h1><a class="toc-backref" href="#id3" id="requirements" name="requirements">Requirements</a></h1> +<p>Currently, Pieforms is written for PHP5. Pieforms will not run in PHP4, however +it is planned that PHP4 support will be added as a separate tree. That way, +those people using PHP5 will gain the full benefits of their choice while those +people who still insist on running PHP4 may also use Pieforms if they need. +<a class="footnote-reference" href="#id2" id="id1" name="id1">[1]</a></p> +<p>If you wish to use the JSForms support, you will need a couple of extra +dependencies:</p> +<ul class="simple"> +<li>The <tt class="docutils literal"><span class="pre">json_encode</span></tt> function, so that Pieforms can reply to JSForm requests. +This dependency is in fact optional - Pieforms includes Services_JSON from PEAR +which contains a pure PHP implementation. However, this is slower than t... [truncated message content] |
From: <ora...@us...> - 2007-03-18 12:35:54
|
Revision: 197 http://svn.sourceforge.net/pieforms/?rev=197&view=rev Author: oracleshinoda Date: 2007-03-18 02:02:03 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Added RST documentation, first cut. Not remotely complete yet. Added Paths: ----------- pieforms-php5/branches/0.2.0/doc/rst/ pieforms-php5/branches/0.2.0/doc/rst/index.rst pieforms-php5/branches/0.2.0/doc/rst/user/ pieforms-php5/branches/0.2.0/doc/rst/user/concepts.rst pieforms-php5/branches/0.2.0/doc/rst/user/configuration.rst pieforms-php5/branches/0.2.0/doc/rst/user/elements.rst pieforms-php5/branches/0.2.0/doc/rst/user/examples.rst pieforms-php5/branches/0.2.0/doc/rst/user/features.rst pieforms-php5/branches/0.2.0/doc/rst/user/usage.rst Added: pieforms-php5/branches/0.2.0/doc/rst/index.rst =================================================================== --- pieforms-php5/branches/0.2.0/doc/rst/index.rst (rev 0) +++ pieforms-php5/branches/0.2.0/doc/rst/index.rst 2007-03-18 09:02:03 UTC (rev 197) @@ -0,0 +1,83 @@ +========================================= + Pieforms_: Advanced web forms made easy +========================================= +:breadcrumbs:`Documentation Home` + +:Author: Nigel McNie +:Contact: ni...@ca... +:Copyright: This document has been placed in the public domain + +The latest copy of the Pieforms documentation may be obtained from SVN: + + ``svn co https://pieforms.svn.sourceforge.net/svnroot/pieforms/pieforms-php5/trunk pieforms`` + +.. _Pieforms: http://pieforms.sourceforge.net/ + +.. contents:: + +General Documentation +===================== + +These files may be of interest to any Pieforms user. + +:README_: The project overview, requirements, and licensing details +:COPYING_: Pieforms is licensed under the `GNU GPL`_, this file contains a full + copy of the license + +.. _README: ../../README +.. _COPYING: ../../COPYING +.. _GNU GPL: http://gnu.org/licenses/gpl.html + +.. _user: + +``user/``: User Documentation +============================= + +These files contain documentation about how to use Pieforms. They will be of +interest to almost any Pieforms user. + +* `Pieforms Concepts and Terms <user/concepts.html>`__ - basic Pieforms + concepts. **Read this first!** +* `Pieforms Feature List <user/features.html>`__ - list of major Pieforms + features +* `Pieforms Configuration <user/configuration.html>`__ - instructions on + installation and basic configuration of Pieforms +* `Basic Usage <user/usage.html>`__ - A step by step guide to writing your + first Pieform +* `Examples of Pieforms <user/examples.html>`_ - examples that show + Pieforms usage, and may give you good ideas +* `Elements <user/elements.html>`__ - General information about elements + including a list of elements that come with Pieforms. +* `Renderers <user/renderers.html>`__ +* `Rules <user/rules.html>`__ +* `i18n <user/i18n.html>`__ + +``ref/``: Reference Material +============================ + +These files contain developer specifications and reference notes that will be +of interest to anyone who wishes to write plugins for Pieforms, or re-implement +it in another language. + +* `Pieforms frontend API documentation (in phpdoc form) <ref/api/index.html>`__ +* `Element API <ref/elements.html>`__ +* `Renderer API <ref/renderers.html>`__ +* `Rule API <ref/rules.html>`__ +* `i18n API <ref/i18n.html>`__ + +``howto/``: Miscellaneous Articles +================================== + +These files contain various documentation about the use of Pieforms in many +situations. + +``dev/``: Core Development Information +====================================== + +These files contain information for Pieforms hackers, administrators and others +involved with the Pieforms source. + +* `Pieforms Coding Standards <dev/coding.html>`__ +* `Pieforms TODO List <dev/todo.html>`__ + +:breadcrumbs:`Documentation Home` Added: pieforms-php5/branches/0.2.0/doc/rst/user/concepts.rst =================================================================== --- pieforms-php5/branches/0.2.0/doc/rst/user/concepts.rst (rev 0) +++ pieforms-php5/branches/0.2.0/doc/rst/user/concepts.rst 2007-03-18 09:02:03 UTC (rev 197) @@ -0,0 +1,307 @@ +============================= + Pieforms Concepts and Terms +============================= +:breadcrumbs:`Documentation Home > Pieform Concepts and Terms` + +:Author: Nigel McNie +:Contact: ni...@ca... +:Copyright: This document has been placed in the public domain + +.. contents:: + +Pieforms is a development of the Mahara_ project, that was later split out into +its own project on sourceforge_. It provides a unified way to create, validate +and process forms all with a common look and feel, with support for pluggable +elements, renderers and validation rules. + +.. _Mahara: http://mahara.org/ +.. _sourceforge: http://pieforms.sourceforge.net/ + +What does that all mean? That's what this document is for - to describe the +overall concepts and ideas behind Pieforms. + +Background +========== + +.. NOTE:: You can skip this section if you don't care for history lessons :) + +In late 2006, the areformentioned Mahara project was in full swing. One of the +technical requirements identified was for a common API for displaying and +processing forms. Nigel was tasked with this job as he had claimed some +familiarity with various PHP form APIs. The three that were given some +consideration were `Drupal's`_ forms API, PEAR's QuickForm_ and Moodle's `form +API`_, which was under development at the time. + +.. _Drupal's: http://drupal.org/ +.. _QuickForm: http://pear.php.net/package/HTML_QuickForm +.. _form API: http://moodle.cvs.sourceforge.net/moodle/moodle/lib/form/ + +Of the three, QuickForm was discarded nearly straight away, due to the large +amount of work to produce any one form, and indifferent experiences by members +of the development team in using it before. Moodle's API was briefly considered +but then dropped, as it appeared to have a similar, "heavy" API and was under +development at the time. This left Drupal's form API as the main contender, and +it probably would have won if it could have been pulled out of Drupal +successfully. Unfortunately, all efforts to extract it so that it would sit on +its own failed - it was too tightly bound to Drupal itself. + +This resulted in the undersirable situation of one form API required vs. none +available. So in an orgy of weekend coding (and over the next few days at +work), Nigel cobbled together a form API with blackjack and hookers. And +amazingly, it worked pretty well. The best part was that writing forms was +insanely quick (including full validation). And soon after, Richard Mansfield +added 'AJAX form' support - forms that submitted very quickly because they were +posted and got their results asynchronously. + +About the same time, Nigel made the elements, renderers and rules fully +pluggable by anyone who wanted to write a new one. It was then that he realised +that this little subproject had turned into a cool implementation of a form +API, that was worth splitting out into its own project. And thus, Pieforms was +born. The name was chosen as a tribute to a leaving team member, whose nick on +IRC was 'pie' :) + +Concepts +======== + +So, what is it that made Pieforms so easy to use and quick to build forms with? +It is because from the outset the library was designed to build forms with as +little work by the user as possible, instead of following a strict 'OO' +approach. As a result, the three or four things you need for a form are: + +* A hash containing the form definition. Basically, this is a big array + describing the overall form properties, and the elements in the form +* An optional callback function that can be used to validate a form submission + (which is practice is not required very often as the inbuilt rules handle most + validation) +* A callback function that handles the submission of the form. This function + can do anything with the submitted values, in the knowledge that the values are + fully validated. +* A call to the ``pieform()`` function, passing the form definition, which + manages the entire form building, validating, submitting and displaying + process. + +Here is an example of a simple form + +.. highlight:: php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'testform', + 'method' => 'post', + 'action' => '', + 'elements' = array( + 'details' => array( + 'type' => 'fieldset', + 'legend' => 'Your Details', + 'elements' => array( + 'fullname' => array( + 'type' => 'text', + 'title' => 'Full name', + 'description' => 'Please enter your full name', + 'rules' => array( + 'required' => true + ) + ), + 'dob' => array( + 'type' => 'date', + 'title' => 'Date of Birth', + 'description' => 'Your date of birth', + 'defaultvalue' => strtotime('1st of January, 1985'), + 'rules' => array( + 'required' => true + ) + ) + ) + ), + + 'submit' => array( + 'type' => 'submit', + 'value' => 'Submit' + ) + ) + ); + + function testform_validate(Pieform $form, $values) { + if (!$form->get_error('dob') && $values['dob'] < strtotime('1st of January, 1950')) { + $form->set_error('dob', 'I will give you another chance to lie about your age, OK? :)'); + } + } + + function testform_submit(Pieform $form, $values) { + print_r($values); + exit; + } + +Here is a description of each part. + +The form definition hash +************************ + +This array contains the definition of the form. In this example the form is +hard coded, and that would be what you would do most of the time, but there's +nothing to stop it from being generated dynamically. The array specifies some +metadata for the whole form, like its name, method and action target, and then +a list of elements that are on the form. Evary form must have a name, this name +is used to call the callback functions. + +More information about the form array is available on a `separate page`_. + +.. _separate page: usage.html + +The ``pieform(...)`` function call +********************************** + +This call builds the form, validates and submits the form if it has been +submitted, and returns the HTML for the form. So in the example above the form +is simply ``echo``'d to the browser, but it could easily be put into a `Smarty +<http://smarty.php.net/>`__ template variable or manipulated any way required. + +The ``testform_validate`` function +********************************** + +This function is named after the form name, with ``_validate`` on the end. It +takes the Pieform object and an array of the submitted values, and can perform +whatever checks are required that cannot be otherwise handled by the inbuilt +form rules. In this case, rather than being a serious rule, a check is made to +give the older viewers a chance to not be so old :). Notice how it uses the +``$form`` object to check for an error beforehand (which might have happened if +the "required" rule was violated, although generally that is quite hard to +violate with the "date" element), and uses it again to set an error on the +form. + +This function is optional, as most of the time you will be able to perform all +the validation you require using rules. Notice in the array in the example how +each element had a 'required' rule. If that was all the validation you +required, you would not need the validate function. There are other rules +available, and it's easy to write your own. + +The ``testform_submit`` function +******************************** + +This function is named after the form name, with ``_submit`` on the end. It +takes an array of the submitted values that have already been validated +successfully according to the validation rules set on the form. From here you +can do almost anything, but the last thing that you should do is either: + +* Redirect the user to another page (perhaps back to this page if you wish to + always display the form to the user), if the form is a standard form +* Reply with ``$form->json_reply(PIEFORM_OK, 'optional message')`` if the form + is a JS form + +Because you will probably be writing a few forms, you should probably write a +wrapper for redirecting the user to another page, to save you time and effort +later. Something like this: + +.. highlight:: php + + function redirect($location) { + header('HTTP/1.1 303 See Other'); + header('Location: ' . $location); + exit; + } + +That is a very simple example, and one you will quite possibly want to extend +it further, perhaps to make specifying the location easier for example. + +Form API Terms +============== + +Pieforms has several components, a basic description of each is given here. + +Elements +******** + +Pieform **elements** are similar to the widgets you have in normal HTML forms, +and in fact all HTML widgets have element implementations in Pieforms. However, +Pieforms does not limit you to using just the standard HTML widgets - you can +write your own elements that have very advanced behaviour, are comprised of +multiple widgets, or do almost anything you like. + +For example, there is a "text" element, which represents a simple HTML +``<input type="text">`` widget. But there is also a "date" widget, which is +rendered as three ``<select>`` widgets for year, month and day, and a +"calendar" widget which is a full-blown popup javascript calendar! The Mahara +project created a "wysiwyg" element that is a full WYSIWYG editor (a native one +will be created for Pieforms soon), and many more besides. + +It's really easy to write your own elements, and they can be reused on any form +that needs them. `More information about elements <elements.html>`__, including +how to write your own, is available. + +Rules +***** + +Rules are used to validate elements. Given the element's value, they check if +the value matches a certain condition. There is a few simple rules implemented, +such as *required*, *minlength* and *maxlength* etc., but again like elements +they are pluggable, so many more can be written. + +Rules may apply differently to different elements, so elements can define a +function that specifies how a rule applies to them, which allows some +flexibility in rule reuse. + +More information on the `rule API and writing your own rules <rules.html>`__ is +available. + +Renderers +********* + +Renderers are used to output the containers that elements are rendered inside. +For example, there is a "table" renderer which puts each element inside a table +row, and a "div" renderer that puts them inside a ``<div>``. Like elements and +rules, these are pluggable to suit your needs. + +One thing that the Mahara project has done is added support for contextual help +for each element. The renderer will render question marks beside each form +element, which when clicked, reveal contextual help for the element. You could +add almost any extra information to each element, to assist your form output - +for example, a description, help text or raw HTML to be output at a certain +point for each element. + +If all that was confusing, check out the `renderers <renderers.html>`__ page +for more information. + +How They Fit Together +===================== + +Here are some statements that might help you understand how a form is put +together using Pieforms. + +A **form** is made up of `elements <elements.html>`__. + +**Elements** are like standard HTML widgets, except they can be more +complicated and comprised of many widgets if necessary. + +Elements are validated by `rules <rules.html>`__. + +Each element in a form is rendered inside some boilerplate HTML provided by a +`renderer <renderers.html>`__. + +When forms are **submitted**, they are **validated** using the **rules** for +each **element**. If validation passes, the form **submit callback** is called +with the values. If validation fails, the form is redisplayed, with the +**renderer** drawing the error messages as returned by the **rule** for each +**element** next to it. + +Other Features of Pieforms +========================== + +As well as customisable elements, renderers and rules, Pieforms has the +following features: + +* Forms can be sent via GET or POST +* Forms can be sent to different pages, as long as the form definition is + available on both pages +* Support for **cancel buttons** - in effect, submit buttons with no + validation applied to them +* **Auto focus** of fields in a form on page load, including focussing the + first element with an error if the form has failed validation +* `JS forms <usage.html#jsform>`__ - forms submitted to a hidden iframe + with the result returned asynchronously, meaning the form behaves very + responsively +* Automatic handling of **tabindex** for each element +* **HTML 4.01 compliance** (XHTML compliance will be added `later + <../dev/todo.html#xhtml>`__) + +:breadcrumbs:`Documentation Home > Pieform Concepts and Terms` Added: pieforms-php5/branches/0.2.0/doc/rst/user/configuration.rst =================================================================== --- pieforms-php5/branches/0.2.0/doc/rst/user/configuration.rst (rev 0) +++ pieforms-php5/branches/0.2.0/doc/rst/user/configuration.rst 2007-03-18 09:02:03 UTC (rev 197) @@ -0,0 +1,181 @@ +======================== + Pieforms Configuration +======================== +:breadcrumbs:`Documentation Home > Pieforms Configuration` + +:Author: Nigel McNie +:Contact: ni...@ca... +:Copyright: This document has been placed in the public domain + +.. contents:: + +This document describes how to install and configure Pieforms for use in your +application. Once you have completed the steps in this document, all of the +features of Pieforms will be available for your use. + +Requirements +============ + +Currently, Pieforms is written for PHP5. Pieforms will not run in PHP4, however +it is planned that PHP4 support will be added as a separate tree. That way, +those people using PHP5 will gain the full benefits of their choice while those +people who still insist on running PHP4 may also use Pieforms if they need. +[#]_ + +If you wish to use the JSForms support, you will need a couple of extra +dependencies: + +* The ``json_encode`` function, so that Pieforms can reply to JSForm requests. + This dependency is in fact optional - Pieforms includes Services_JSON from PEAR + which contains a pure PHP implementation. However, this is slower than the + native JSON extension for PHP, so if you have that extension it is a bonus. PHP + 5 >= 5.2 contains the JSON extension built in, so you do not need to worry if + you are using a version above that. +* The ``Base``, ``Iter``, ``Style``, ``DOM`` and ``Async`` modules of `MochiKit + <http://mochikit.com/>`__, greater than version 1.3.1. A packed version of + MochiKit containing just these modules is available for your convenience in the + ``static/core/MochiKit`` directory, however you can use your own MochiKit if + you require other modules. + +Installation +============ + +To install Pieforms: + +1. Copy the ``pieform.php`` file and the ``pieform`` diretory (contained in the + ``src`` directory of the standard Pieforms distribution) to somewhere in your + application's directory structure. Also copy the ``JSON`` directory to the same + place if you do not have the JSON extension for PHP available and want to use + the JS form submission support. +2. If you wish to use the more advanced javascript widgets (such as the + calendar), or the JS form submission support, copy the ``static`` directory + contents to some place where your application can link to the appropriate + javascript files. + +And you're done! + +Using Pieforms on a Page +======================== + +On any page in your application where a Pieform is to be made: + +* Make sure that the MochiKit javascript file is sourced by a <script> tag in + the output of the page, if you are using JS forms, autofocus, or any other + javascript effect. +* Also make sure that ``pieforms.js`` is included (which is located in + ``static/core/``), if you are using javascript effects. +* Include the ``pieform.php`` file. +* You will need to call ``pieform_get_headdata()`` somewhere. This will return + an array of ``<script>`` tags, ``<link>`` tags and other things that need to go + in the ``<head>`` of your document somewhere. + +As long as you have followed all of those steps, all features of Pieforms +should be available. + +Configuration +============= + +Pieforms provides a way for you to configure how a "default" form should be set +up, as well as the "default" configuration for each element. You can also write +a function that is called by all forms for validation, which is useful if you +always have an element in all of your forms. + +If none of the next section makes too much sense, don't worry too much. +Instead, skip on to the `step by step guide <usage.html>`__ to creating +Pieforms, and read that. After having read that, you will quickly see the +benefits of the configuration functions provided below. + +Configuring a Default Form +************************** + +To configure a default form, you should write a ``pieform_configure()`` +function. This function should return what looks like the definition of a +Pieform, that will be used as the default for all forms. You could use this to, +for example, turn 'autofocus' on for all forms by default. Here is an example: + +.. highlight:: php/php5 + + function pieform_configure() { + // This is just a variable specific to your application, + // for example purposes. + global $LIBDIR; + + return array( + // Make all forms by default POST. The default for Pieforms, + // as for normal HTML forms, is GET. + 'method' => 'post', + + // Autofocus the first field of the form on page load, or the + // first field with an error if there is an error. If there is + // more than one form on a page, only the first is focused. + 'autofocus' => true, + + // Add the element type to the list of classes for each element. + // For example, the 'text' element will get a class of 'text'. Useful + // for styling forms when you have to support broken IE6. + 'elementclasses' => true, + + // Look in this directory as well as the default for plugins. So you + // can keep your elements/renderers/rules separate from the Pieforms + // ones. + 'configdirs' => $LIBDIR . 'form/', + + // You can add elements that will be in all forms. Here's the prime + // example of why you would want to... + 'elements' => array( + // Using a session key for forms prevents CSRF (check google or + // wikipedia for an explanation). Without this, you may as well + // invite hackers in to play with your users. + 'sesskey' => array( + 'type' => 'hidden', + // This function specific to your application + 'value' => get_sesskey() + ) + ) + ); + } + +Validation for All Forms +************************ + +Of course, with the session key in the previous section as a good example, it +would get boring pretty quickly if you had to add validation to it to all +forms. Pieforms allows you to define the ``pieform_validate`` function that +will be called whenever any form is validated to do any validation that should +be done for all forms. + +.. highlight:: php/php5 + + function pieform_validate(Pieform $form, $values) { + if (!isset($values['sesskey'])) { + throw new Exception('No session key'); + } + $sesskey = get_sesskey(); + if ($sesskey && $sesskey != $values['sesskey']) { + throw new Exception('Invalid session key'); + } + } + +Configuring elements +******************** + +Some elements (such as the ``calendar``), take configuration parameters that +you may not want to specify everywhere that they are used. To prevent +duplication, you can specify a function for each element to configure it. + +.. highlight:: php/php5 + + function pieform_element_calendar_configure($element) { + $element['jsroot'] = '/js/jscalendar/'; + $element['themefile'] = '/style/calendar.css'; + $element['imagefile'] = '/img/calendar.gif'; + $element['language'] = 'en'; + return $element; + } + +See the documentation of each element for more information about what you can +configure them to do. + +.. [#] The author works with and has authored many PHP4 projects in his time, thus eventually Pieforms **will** be ported for some of these projects (or for a new project if PHP4 is a requirement). Once you've used Pieforms you won't want to use anything else :) + +:breadcrumbs:`Documentation Home > Pieforms Configuration` Added: pieforms-php5/branches/0.2.0/doc/rst/user/elements.rst =================================================================== --- pieforms-php5/branches/0.2.0/doc/rst/user/elements.rst (rev 0) +++ pieforms-php5/branches/0.2.0/doc/rst/user/elements.rst 2007-03-18 09:02:03 UTC (rev 197) @@ -0,0 +1,113 @@ +=================== + Pieforms Elements +=================== +:breadcrumbs:`Documentation Home > Pieforms Elements` + +:Author: Nigel McNie +:Contact: ni...@ca... +:Copyright: This document has been placed in the public domain + +.. contents:: + +This document describes how elements fit into the Pieforms architecture, how you use them, and how you can write your own to suit your needs. + +Overview +======== + +As you may be aware by now, if you have used Pieforms for a little while or have read the documentation that comes before this, Pieform elements represent distinct part of a form. It takes one or more elements to make up a form, but normally at least two - any elements the form has plus some kind of "submit" element. For example, a form may have three elements - a text box, a select dropdown, and a submit button. + +The important thing to remember is that Pieform elements do not necessarily correspond to the standard HTML form widgets. In fact, they are a lot more powerful. While it is almost guaranteed that elements will contain at least one HTML widget, in reality they can contain almost anything you want. For the Mahara project, elements were written that: + +* Made AJAX requests to populate select dropdowns +* Used smarty templating to lay themselves out +* Displayed a calendar for picking a date +* Allowed users to maintain a list of e-mail addresses, and pick a "primary" address + +Once you understand how elements work, it will be easy for you to write your own. All you need to make sure of is that each element deals with one separate task. A good rule of thumb is to make elements that can return one value or one array of values, though in some cases you may relax this rule (for example, the email list element described above returns both a list of e-mail addresses and which one is the primary address). + +Using Elements +============== + +To use an element in your form, you name it when declaring the type of one of your form elements. + +.. highlight:: php/php5 + + <?php + + $form = array( + 'name' => 'myform', + 'elements' => array( + 'myelement' => array( + // Choose the type of the element here + 'type' => 'text', + // Any other configuration for the element goes here... + ) + ) + ); + + ?> + +In the above example, the element has been declared as having a type of 'text'. The text element is for a standard HTML text input. You put any other configuration for the element in there as well. For example, you can declare the default value for the element using ``defaultvalue`` or its size using ``size``. The list varies per element, but the major ones are listed here. + +Common Configuration Items for Elements +--------------------------------------- + +.. NOTE:: These items are supported by most of the standard elements, although their behaviour may vary between elements + ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| Item | Description | ++==================+========================================================================================================================================================================================================+ +| ``defaultvalue`` | What value the element should have by default | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``value`` | The value the element should have *regardless of what the user submits* | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``accesskey`` | What value to use for the ``accesskey`` attribute of the element | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``class`` | What value to use for the ``class`` attribute of the element | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``dir`` | What value to use for the ``dir`` attribute of the element | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``lang`` | What value to use for the ``lang`` attribute of the element | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``onclick`` | What value to use for the ``onclick`` attribute of the element. Note that it is preferred that you use MochiKit's event handling library if you can. | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``style`` | What value to use for the ``style`` attribute of the element | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``name`` | You can name your elements using the ``name`` item, but the name for the element is usually sourced by the array key it was declared with. | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``id`` | What to use as an ID for the element. Pieforms gives all your elements IDs, so you generally should not set one this way. | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``size`` | What to use for the "size" of an element. The meaning varies from element to element, but generally means what the ``size`` attribute means for the element in HTML. | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| ``tabindex`` | What to use for the tabindex of an element. Pieforms manages tabindex automatically, and you can set the tabindex for every element in the form elsewhere, so generally there is no need to set this. | ++------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ + +Supported Elements +------------------ + +The elements that you can use will depend on several things, such as what version of Pieforms you have, what elements you have written or downloaded, and what you have set the search path for plugins as. Here is a list of Pieform elements that come with Pieforms. + +* button +* bytes +* calendar +* cancel +* checkbox +* date +* expiry +* fieldset +* file +* hidden +* html +* image +* password +* radio +* select +* submitcancel +* submit +* textarea +* text + +.. TODO:: Link to docs for the elements, generate the list programatically + +Most of these elements correspond to basic HTML elements +:breadcrumbs:`Documentation Home > Pieforms Elements` Added: pieforms-php5/branches/0.2.0/doc/rst/user/examples.rst =================================================================== --- pieforms-php5/branches/0.2.0/doc/rst/user/examples.rst (rev 0) +++ pieforms-php5/branches/0.2.0/doc/rst/user/examples.rst 2007-03-18 09:02:03 UTC (rev 197) @@ -0,0 +1,16 @@ +=================== + Pieforms Examples +=================== +:breadcrumbs:`Documentation Home > Pieforms Examples` + +:Author: Nigel McNie +:Contact: ni...@ca... +:Copyright: This document has been placed in the public domain + +.. contents:: + +There is no examples yet, but they will be coming soon! Check the `concepts +<concepts.html>`__ page for a simple example, and you could also `download +Mahara <http://mahara.org/>`__ and see the many forms written for it. + +:breadcrumbs:`Documentation Home > Pieforms Examples` Added: pieforms-php5/branches/0.2.0/doc/rst/user/features.rst =================================================================== --- pieforms-php5/branches/0.2.0/doc/rst/user/features.rst (rev 0) +++ pieforms-php5/branches/0.2.0/doc/rst/user/features.rst 2007-03-18 09:02:03 UTC (rev 197) @@ -0,0 +1,96 @@ +=================== + Pieforms Features +=================== +:breadcrumbs:`Documentation Home > Pieforms Features` + +:Author: Nigel McNie +:Contact: ni...@ca... +:Copyright: This document has been placed in the public domain + +.. contents:: + +This document outlines the major features that Pieforms has, with a brief +description of each one and links to more information for them. + +Simple To Use API +================= + +For the vast majority of cases, all you ever see of the Pieforms API is the +``pieform($form)`` function call. Most of the work is specific to your +application - the definition of the form, and the function to handle successful +submission. This means you can concentrate your efforts on the important parts +- how your form is defined, and what to do when the user submits it properly. + +Practically, this means that: + +* Prototyping is really easy - if you need to prototype a page, it won't take + you very long to hack up a display-only form +* The submit function can follow the so-called "happy path" - because you know + that all the data is validated, your function can concern itself entirely with + the job of writing information to the database, sending e-mail, logging a user + in, or anything else you need. + +The form definition itself is intuitive, making it really easy to add, remove +and re-order the elements in your form in about a minute of work - which is how +long it **should** take. And with all the available elements, renderers and +rules pre-made for your convenience, form building will often just be a case of +selecting the parts you require. + +And if you find you need something that isn't available, the APIs for making +new plugins are simple and consistent, making this job easy as well. Combined +with `MochiKit <http://mochikit.com/>`__ on the client side, you will find +making new plugins dead easy! + +Pluggable and Extensable +======================== + +Each of the three main components to a Pieform - elements, renderers and rules +- are pluggable. This means if Pieforms doesn't provide something you require, +you can just write it yourself. Pieforms provides a method for you to list +directories where plugins are located, meaning you can keep your creations +separate from the core Pieforms plugins if you like. And if you think your +plugin is neat and could be used by others, you could submit it to Pieforms as +a `feature request +<http://sourceforge.net/tracker/?group_id=182497&atid=901456>`__, and it could +be included in the next release for everyone to enjoy. + +Asynchronous Forms +================== + +By simply flipping a switch, you can turn your forms from being standard +``POST`` forms into snappy, responsive "Javascript Forms" (or JSForms as +Pieforms knows them). Rather than doing a full ``POST`` every time the form is +submitted, the form data is submitted to a hidden iframe, and the result +returned as JSON. This makes the form "feel" much faster and responsive, +especially when the validation may be complex and the user may have to have +several goes at submitting a form before they get it right. + +This also frees your page to perform actions using javascript during and after +the form submission. For example, you could place a spinner on the page +somewhere or disable the submit button and replace the text with 'processing +form...' when the form is submitted, and then display a message when the form +is successfully submitted. + +Full Internationalisation (i18n) +================================ + +Though there is not a lot to translate, Pieforms has i18n support, so the rule +messages can be in your native language if you need. Elements also support i18n +where required - for example, the calendar element supports different +languages. Although the only supported language at the moment is "en.utf8", it +will take only around 10 minutes to add new languages. Ask on the mailing list +or in the forums! + +HTML 4.01 Compliance +==================== + +Pieforms generates HTML 4.01 compatible output. It does not support XHTML at +the moment, but the author reckons this will only take an hour of work, if you +ask nicely :). + +Pieforms uses the ``tabindex`` attribute for form elements, meaning that +keyboard users are not forgotten. Pieforms also supports auto-focusing the +first field of a form on page load, and auto-focusing the first field with an +error on it if there is one. + +:breadcrumbs:`Documentation Home > Pieforms Features` Added: pieforms-php5/branches/0.2.0/doc/rst/user/usage.rst =================================================================== --- pieforms-php5/branches/0.2.0/doc/rst/user/usage.rst (rev 0) +++ pieforms-php5/branches/0.2.0/doc/rst/user/usage.rst 2007-03-18 09:02:03 UTC (rev 197) @@ -0,0 +1,526 @@ +================ + Pieforms Usage +================ +:breadcrumbs:`Documentation Home > Pieforms Usage` + +:Author: Nigel McNie +:Contact: ni...@ca... +:Copyright: This document has been placed in the public domain + +.. contents:: + +This document takes you through the creation of a Pieform, step by step. After +reading this document, you should be able to put together all manner of +Pieforms, and you will be ready to begin learning how to create your own +plugins for your own needs. + +Before You Begin... +=================== + +Make sure that you have `read the concepts document <concepts.html>`__, so that +you understand the basic ideas behind how Pieforms works. Also make sure you +have `installed <configuration.html>`__ Pieforms, of course! + +Your First Pieform +================== + +For the sake of argument, let us assume that you are writing a blogging application, and that your current task is to write a form into which new posts will be entered. This form will consist of: + +* A text box, for the subject +* A textarea, for the post content +* A multiple-select dropdown, for choosing categories for the post +* A date field for choosing the date on which the post will become viewable, defaulting to the current date +* A submit and cancel button + +Also, for the sake of argument, let us assume that the category selection and date fields are optional and not really used that much, so we will place them in a fieldset and collapse it by default, to make the form seem simpler for general use. + +So, given these requirements, let's get started! + +The Basics +---------- + +We shall start with the basic page shell, and build the pieces as required. Here is the most basic shell: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array()); + + ?> + +And here is the output you get when running this: + +[insert screenshot here of boom] + +Whoops! Pieforms forms **must** have a name. This name is used on the client side to identify the form, and on the server side to provide unique names for the validation/submission callbacks. More on those later, but for now let's add some of the most basic parameters required: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'blogpost', + 'method' => 'post' + )); + + ?> + +[insert screenshot of boom] + +So now the form has a name, and will be sent by POST when submitted. But it has no elements! There's not too much point in having a form that does not have an element, so lets add the title field and submit/cancel buttons. + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'blogpost', + 'method' => 'post', + 'elements' => array( + 'title' => array( + 'type' => 'text', + 'title' => 'Post Title' + ), + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + ) + ) + )); + + ?> + +[insert screenshot of yay] + +Now we have some concrete progress, at last! We now have a single text box, with a submit and cancel button under it. Compare how much effort it took to add these elements with how you would normally make forms. I hope you are already seeing how quick this is! + +Now let's try submitting the form: + +[insert screenshot of boom] + +We have not specified the function that gets run when the form is submitted. This function has the name ``[formname]_submit``, and once it is done it should somehow redirect the user to another page (or redirect back to the same page if you wish, but it must be a redirect so that the form state is cleared), or exit the script. For now we will just show a success page: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'blogpost', + 'method' => 'post', + 'elements' => array( + 'title' => array( + 'type' => 'text', + 'title' => 'Post Title' + ), + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + ) + ) + )); + + function blogpost_submit(Pieform $form, $values) { + echo <<<EOF + <p>Congratulations! New post entered. <a href="">Back to enter another one</a>...</p> + EOF; + exit; + } + + ?> + +Please pardon my terrible HTML, this is only an example :). Now, when you submit the form: + +[screenshot of success] + +That's much better. Of course, the submit function should have inserted the blog post into the database before displaying this message, but I'll leave that detail as an exercise for the reader. + +But what about the cancel button? + +[screenshot of cancel boom] + +Not so great, luckily Pieforms tells you what you need to do to fix that. While we're at it, let's add the textarea for the post content: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'blogpost', + 'method' => 'post', + 'elements' => array( + 'title' => array( + 'type' => 'text', + 'title' => 'Post Title' + ), + 'content' => array( + 'type' => 'textarea', + 'title' => 'Content' + ), + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + 'goto' => $_SERVER['SCRIPT_NAME'] + ) + ) + )); + + function blogpost_submit(Pieform $form, $values) { + echo <<<EOF + <p>Congratulations! New post entered. <a href="">Back to enter another one</a>...</p> + EOF; + exit; + } + + ?> + +[insert screenshot of form] + +You will get the result above both when you view and cancel the form. Of course, your cancel button could redirect elsewhere, or put a message in the session that is displayed on the next page, using the cancel function ``[formname]_cancel_submit`` rather than ``'goto'`` on the element. + +So now all that remains is the category multiple select and the date for when the post will be published. These should be in a fieldset: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'blogpost', + 'method' => 'post', + 'elements' => array( + 'title' => array( + 'type' => 'text', + 'title' => 'Post Title' + ), + 'content' => array( + 'type' => 'textarea', + 'title' => 'Content' + ), + 'optional' => array( + 'type' => 'fieldset', + 'title' => 'Advanced Options...', + 'collapsable' => true, + 'collapsed' => true, + 'elements' => array( + 'categories' => array( + 'type' => 'select', + 'title' => 'Categories', + 'multiple' => true, + 'size' => 5, + 'values' => array( + 1 => 'Personal', + 2 => 'Rants', + 3 => 'Politics', + 4 => 'Religion', + 5 => 'Science', + 6 => 'Arts' + ) + ), + 'publishdate' => array( + 'type' => 'date', + 'title' => 'Publish Date' + ) + ) + ), + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + 'goto' => $_SERVER['SCRIPT_NAME'] + ) + ) + )); + + function blogpost_submit(Pieform $form, $values) { + echo <<<EOF + <p>Congratulations! New post entered. <a href="">Back to enter another one</a>...</p> + EOF; + exit; + } + + ?> + +[insert screenshot] + +Adding a Touch of Class +----------------------- + +Now the whole form is layed out, including the collapsable fieldset. Cool! But we are not finished yet. The form has no rules attached to it (other than a hidden rule on the multiselect box to automatically check that the submitted value is in the array of values), and could be improved with a bit of javascript love. On the rule side, let's make the title and content of the post required and the publish date be later than the current time. For javascript improvement, we can make the textarea resizable and auto focus the title element on page load. + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'blogpost', + 'method' => 'post', + 'autofocus' => true, + 'elements' => array( + 'title' => array( + 'type' => 'text', + 'title' => 'Post Title', + 'rules' => array('required' => true) + ), + 'content' => array( + 'type' => 'textarea', + 'title' => 'Content', + 'rules' => array('required' => true), + 'resizable' => true + ), + 'optional' => array( + 'type' => 'fieldset', + 'title' => 'Advanced Options...', + 'collapsable' => true, + 'collapsed' => true, + 'elements' => array( + 'categories' => array( + 'type' => 'select', + 'title' => 'Categories', + 'multiple' => true, + 'size' => 5, + 'values' => array( + 1 => 'Personal', + 2 => 'Rants', + 3 => 'Politics', + 4 => 'Religion', + 5 => 'Science', + 6 => 'Arts' + ) + ), + 'publishdate' => array( + 'type' => 'date', + 'title' => 'Publish Date' + ) + ) + ), + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + 'goto' => $_SERVER['SCRIPT_NAME'] + ) + ) + )); + + function blogpost_validate(Pieform $form, $values) { + if ($values['publishdate'] && $values['publishdate'] < time()) { + $form->set_error('publishdate', 'Sorry, your publish date must be in the future'); + } + } + + function blogpost_submit(Pieform $form, $values) { + echo <<<EOF + <p>Congratulations! New post entered. <a href="">Back to enter another one</a>...</p> + EOF; + exit; + } + + ?> + +Not too much added, and pretty much everything we wanted is implemented. The title and content are now required - try submitting the form without them set. There's no easy rule for checking that a value is greater than another just yet, so we added a 'validate' function which sets an error on the form if the publish date is not in the future. It took one line to make the textarea resizable, and just one more to make the title element focus on page load. Note that we specified 'autofocus' to be **true** - this means that the first element in the form will be focussed on page load. You can specify an element by name if you want that particular element to be focussed on page load. + +The Finishing Touches +--------------------- + +Programatically, the form is done (except for any actualy logic to save the data somewhere). Now all you need it a bit of CSS magic, and you're done! + +[insert CSS code here] + +[insert screenshot here] + +From zero to form in very short order - when you get good at writing forms and Pieforms is already integrated into your software, the above form will be very quick indeed to create. + +Now let's move on to another form, this time one that will have a bit more of an 'AJAX feel'. + +A Form With Wings +================= + +Happy with the form you made in the previous section, you now move on to your next task - a settings page for the admin section of your blog software. The form is for managing some global information about file uploads. As you will see, a little bit of Pieforms magic makes this form trivial to write. + +Overview +-------- + +The form will have the following fields for an administrator to fill out: + +* A global toggle, for whether file uploading is enabled or disabled +* A text field, in which the user can put the path to the ``file`` binary, used for checking the file type of uploaded files +* An element for inputting the quota that each user is allowed + +Let's get started with the boilerplate: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'filesettings', + 'method' => 'post', + 'elements' => array( + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + ) + ) + )); + + function filesettings_submit(Pieform $form, $values) { + echo '<pre>'; + print_r($values); + echo '</pre>'; + echo '<a href="">Back to try again</a>'; + exit; + } + + ?> + +Now to add the elements: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'filesettings', + 'method' => 'post', + 'elements' => array( + 'enabled' => array( + 'type' => 'checkbox', + 'title' => 'File Uploading Enabled?', + 'defaultvalue' => true + ), + 'pathtofile' => array( + 'type' => 'text', + 'title' => 'Path to the "file" command', + 'defaultvalue' => '/usr/bin/file' + ), + 'quota' => array( + 'type' => 'bytes', + 'title' => 'User Quota', + 'defaultvalue' => 10 * 1024 * 1024 + ), + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + ) + ) + )); + + function filesettings_submit(Pieform $form, $values) { + echo '<pre>'; + print_r($values); + echo '</pre>'; + echo '<a href="">Back to try again</a>'; + exit; + } + + ?> + +Nothing too dramatic there... but what about that 'bytes' element? + +The 'bytes' element is the first example of how **elements do not have to correspond to HTML form widgets**. In fact, the 'bytes' element is made up of both a (short) text box and a select dropdown. Users can input the quota in either bytes, kilobytes or megabytes using this element, depending on what suits them. + +This form was not hard to make, given the previous example, but it does seem like such a waste to have to do a whole round trip to the server to save the values each time. Lets make this form a 'jsform', for speed. + +Making a Form Work Quickly +-------------------------- + +Making the form submit via a hidden iframe takes one more line of code in the form definition, and a small change to the submit function: + +.. highlight:: php/php5 + + <?php + + require_once('pieform.php'); + + echo pieform(array( + 'name' => 'filesettings', + 'method' => 'post', + 'jsform' => true, + 'elements' => array( + 'enabled' => array( + 'type' => 'checkbox', + 'title' => 'File Uploading Enabled?', + 'defaultvalue' => true + ), + 'pathtofile' => array( + 'type' => 'text', + 'title' => 'Path to the "file" command', + 'defaultvalue' => '/usr/bin/file' + ), + 'quota' => array( + 'type' => 'bytes', + 'title' => 'User Quota', + 'defaultvalue' => 10 * 1024 * 1024 + ), + 'submit' => array( + 'type' => 'submitcancel', + 'value' => array('Enter New Post', 'Cancel') + ) + ) + )); + + function filesettings_submit(Pieform $form, $values) { + if ($form->get_property('jsform')) { + $form->json_reply(PIEFORM_OK, 'Form saved successfully'); + } + echo '<pre>'; + print_r($values); + echo '</pre>'; + echo '<a href="">Back to try again</a>'; + exit; + } + + ?> + +Give it a try. What works, and what doesn't? + +All that was added was the one line, ``'jsform' => true`` in the form definition, and the one if statement in the submit function. But behind the scenes, the whole submission process of the form as changed. Now, when you click the submit button, the following things happen: + +* A hidden <iframe> is created +* The form target is changed so that the form submits to the newly created <iframe> +* A javascript function is created that will handle the reply, when it arrives +* The form is submitted +* The reply that comes back to the <iframe> calls the function registered to handle the reply + +You send a reply to a jsform using the ``$form->json_reply`` method. Pretty much all of the time, the first parameter will be ``PIEFORM_OK``. The second parameter contains data that you can send back to the application. + +Speaking of that data - why did you not see a happy success message like you were expecting? Well, Pieforms may be pretty smart, but it's not the next Einstein. You haven't told it *how* to deal with this data. You need to add one more line to the form definition, and write a javascript function: + +[insert example here] + +And this is the result, when you submit the form: + +[insert screenshot here] + +Excellent! There's only one little issue now. Because you're a great believer in not using tables where not required, you want to change how the form is layed out. All you need to do is add one line to change the renderer: + +[insert example here] + +[insert screenshot here] + +Pieforms comes with a few renderers by default, they're in the ``pieform/renderers`` directory. Try them all, and see how the layout of your form changes. + +Conclusion +========== + +As you can see, Pi... [truncated message content] |
From: <ora...@us...> - 2007-03-18 12:35:35
|
Revision: 195 http://svn.sourceforge.net/pieforms/?rev=195&view=rev Author: oracleshinoda Date: 2007-03-18 01:57:21 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Changed index page to redirect user to real documentation Modified Paths: -------------- pieforms-php5/branches/0.2.0/doc/index.html Modified: pieforms-php5/branches/0.2.0/doc/index.html =================================================================== --- pieforms-php5/branches/0.2.0/doc/index.html 2007-03-18 08:56:35 UTC (rev 194) +++ pieforms-php5/branches/0.2.0/doc/index.html 2007-03-18 08:57:21 UTC (rev 195) @@ -1,8 +1,8 @@ <html> <head> - <title>Documentation</title> + <meta http-equiv="refresh" content="0; url=html/"> </head> <body> - <p>Pieforms documentation will be coming soon... for now check <a href="https://eduforge.org/wiki/wiki/mahara/wiki?pagename=FormAPI">the Mahara wiki</a>. It's a bit out of date, but I will be providing new documentation soon.</p> + <p><a href="html/">HTML Documentation</a></p> </body> </html> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-03-18 12:01:09
|
Revision: 200 http://svn.sourceforge.net/pieforms/?rev=200&view=rev Author: oracleshinoda Date: 2007-03-18 02:05:51 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Added GeSHi as an external project, for generating the documentation Property Changed: ---------------- pieforms-php5/branches/0.2.0/doc/ Property changes on: pieforms-php5/branches/0.2.0/doc ___________________________________________________________________ Name: svn:externals + geshi https://geshi.svn.sourceforge.net/svnroot/geshi/trunk/geshi-src/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-03-12 22:50:37
|
Revision: 193 http://svn.sourceforge.net/pieforms/?rev=193&view=rev Author: oracleshinoda Date: 2007-03-12 15:50:37 -0700 (Mon, 12 Mar 2007) Log Message: ----------- Merged i18n fixes from trunk Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform/elements/calendar.php pieforms-php5/branches/0.2.0/src/pieform/rules/integer.php pieforms-php5/branches/0.2.0/src/pieform/rules/maxlength.php pieforms-php5/branches/0.2.0/src/pieform/rules/minlength.php pieforms-php5/branches/0.2.0/src/pieform/rules/regex.php Modified: pieforms-php5/branches/0.2.0/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/elements/calendar.php 2007-03-12 22:46:39 UTC (rev 192) +++ pieforms-php5/branches/0.2.0/src/pieform/elements/calendar.php 2007-03-12 22:50:37 UTC (rev 193) @@ -134,7 +134,7 @@ $value = strtotime($global[$name]); if ($value === false) { - $form->set_error($name, 'TODO (error for invalid calendar value)'); + $form->set_error($name, $form->i18n('element', 'calendar', 'invalidvalue', $element)); return null; } return $value; @@ -147,4 +147,15 @@ return null; } +/** + * i18n for calendar + */ +function pieform_element_calendar_i18n() { + return array( + 'en.utf8' => array( + 'invalidvalue' => 'Invalid date/time specified' + ) + ); +} + ?> Modified: pieforms-php5/branches/0.2.0/src/pieform/rules/integer.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/rules/integer.php 2007-03-12 22:46:39 UTC (rev 192) +++ pieforms-php5/branches/0.2.0/src/pieform/rules/integer.php 2007-03-12 22:50:37 UTC (rev 193) @@ -39,7 +39,7 @@ } } -function pieform_i18n_rule_integer() { +function pieform_rule_integer_i18n() { return array( 'en.utf8' => array( 'integer' => 'The field must be an integer' Modified: pieforms-php5/branches/0.2.0/src/pieform/rules/maxlength.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/rules/maxlength.php 2007-03-12 22:46:39 UTC (rev 192) +++ pieforms-php5/branches/0.2.0/src/pieform/rules/maxlength.php 2007-03-12 22:50:37 UTC (rev 193) @@ -39,7 +39,7 @@ } } -function pieform_i18n_rule_maxlength() { +function pieform_rule_maxlength_i18n() { return array( 'en.utf8' => array( 'maxlength' => 'This field must be at most %d characters long' Modified: pieforms-php5/branches/0.2.0/src/pieform/rules/minlength.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/rules/minlength.php 2007-03-12 22:46:39 UTC (rev 192) +++ pieforms-php5/branches/0.2.0/src/pieform/rules/minlength.php 2007-03-12 22:50:37 UTC (rev 193) @@ -39,7 +39,7 @@ } } -function pieform_i18n_rule_minlength() { +function pieform_rule_minlength_i18n() { return array( 'en.utf8' => array( 'minlength' => 'This field must be at least %d characters long', Modified: pieforms-php5/branches/0.2.0/src/pieform/rules/regex.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/rules/regex.php 2007-03-12 22:46:39 UTC (rev 192) +++ pieforms-php5/branches/0.2.0/src/pieform/rules/regex.php 2007-03-12 22:50:37 UTC (rev 193) @@ -40,7 +40,7 @@ } } -function pieform_i18n_rule_regex() { +function pieform_rule_regex_i18n() { return array( 'en.utf8' => array( 'regex' => 'This field is not in valid form' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-03-12 22:46:39
|
Revision: 192 http://svn.sourceforge.net/pieforms/?rev=192&view=rev Author: oracleshinoda Date: 2007-03-12 15:46:39 -0700 (Mon, 12 Mar 2007) Log Message: ----------- Fixed up i18n for several elements and rules Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/calendar.php pieforms-php5/trunk/src/pieform/rules/integer.php pieforms-php5/trunk/src/pieform/rules/maxlength.php pieforms-php5/trunk/src/pieform/rules/minlength.php pieforms-php5/trunk/src/pieform/rules/regex.php Modified: pieforms-php5/trunk/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/calendar.php 2007-02-27 04:47:10 UTC (rev 191) +++ pieforms-php5/trunk/src/pieform/elements/calendar.php 2007-03-12 22:46:39 UTC (rev 192) @@ -134,7 +134,7 @@ $value = strtotime($global[$name]); if ($value === false) { - $form->set_error($name, 'TODO (error for invalid calendar value)'); + $form->set_error($name, $form->i18n('element', 'calendar', 'invalidvalue', $element)); return null; } return $value; @@ -147,4 +147,15 @@ return null; } +/** + * i18n for calendar + */ +function pieform_element_calendar_i18n() { + return array( + 'en.utf8' => array( + 'invalidvalue' => 'Invalid date/time specified' + ) + ); +} + ?> Modified: pieforms-php5/trunk/src/pieform/rules/integer.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/integer.php 2007-02-27 04:47:10 UTC (rev 191) +++ pieforms-php5/trunk/src/pieform/rules/integer.php 2007-03-12 22:46:39 UTC (rev 192) @@ -39,7 +39,7 @@ } } -function pieform_i18n_rule_integer() { +function pieform_rule_integer_i18n() { return array( 'en.utf8' => array( 'integer' => 'The field must be an integer' Modified: pieforms-php5/trunk/src/pieform/rules/maxlength.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/maxlength.php 2007-02-27 04:47:10 UTC (rev 191) +++ pieforms-php5/trunk/src/pieform/rules/maxlength.php 2007-03-12 22:46:39 UTC (rev 192) @@ -39,7 +39,7 @@ } } -function pieform_i18n_rule_maxlength() { +function pieform_rule_maxlength_i18n() { return array( 'en.utf8' => array( 'maxlength' => 'This field must be at most %d characters long' Modified: pieforms-php5/trunk/src/pieform/rules/minlength.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/minlength.php 2007-02-27 04:47:10 UTC (rev 191) +++ pieforms-php5/trunk/src/pieform/rules/minlength.php 2007-03-12 22:46:39 UTC (rev 192) @@ -39,7 +39,7 @@ } } -function pieform_i18n_rule_minlength() { +function pieform_rule_minlength_i18n() { return array( 'en.utf8' => array( 'minlength' => 'This field must be at least %d characters long', Modified: pieforms-php5/trunk/src/pieform/rules/regex.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/regex.php 2007-02-27 04:47:10 UTC (rev 191) +++ pieforms-php5/trunk/src/pieform/rules/regex.php 2007-03-12 22:46:39 UTC (rev 192) @@ -40,7 +40,7 @@ } } -function pieform_i18n_rule_regex() { +function pieform_rule_regex_i18n() { return array( 'en.utf8' => array( 'regex' => 'This field is not in valid form' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-27 04:47:11
|
Revision: 191 http://svn.sourceforge.net/pieforms/?rev=191&view=rev Author: oracleshinoda Date: 2007-02-26 20:47:10 -0800 (Mon, 26 Feb 2007) Log Message: ----------- Merged Jeremy's fix to trunk Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-02-27 04:42:39 UTC (rev 190) +++ pieforms-php5/trunk/src/pieform.php 2007-02-27 04:47:10 UTC (rev 191) @@ -524,7 +524,7 @@ $submitted = false; foreach ($this->get_elements() as $element) { if (!empty($element['submitelement']) && isset($global[$element['name']])) { - $function = "{$this->name}_submit_{$element['name']}"; + $function = "{$this->data['successcallback']}_{$element['name']}"; if (function_exists($function)) { $function($this, $values); $submitted = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-27 04:42:40
|
Revision: 190 http://svn.sourceforge.net/pieforms/?rev=190&view=rev Author: oracleshinoda Date: 2007-02-26 20:42:39 -0800 (Mon, 26 Feb 2007) Log Message: ----------- When the successcallback is overridden, allow each submit button to have its own success function named after the overridden name (thanks to Jeremy for that) Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform.php Modified: pieforms-php5/branches/0.2.0/src/pieform.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-19 23:17:52 UTC (rev 189) +++ pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-27 04:42:39 UTC (rev 190) @@ -524,7 +524,7 @@ $submitted = false; foreach ($this->get_elements() as $element) { if (!empty($element['submitelement']) && isset($global[$element['name']])) { - $function = "{$this->name}_submit_{$element['name']}"; + $function = "{$this->data['successcallback']}_{$element['name']}"; if (function_exists($function)) { $function($this, $values); $submitted = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-19 23:17:52
|
Revision: 189 http://svn.sourceforge.net/pieforms/?rev=189&view=rev Author: oracleshinoda Date: 2007-02-19 15:17:52 -0800 (Mon, 19 Feb 2007) Log Message: ----------- Added support for disabling individual option values in a select box. Also added support for labelling options, which unfortunately isn't supported by any common user agent yet. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/select.php Modified: pieforms-php5/trunk/src/pieform/elements/select.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/select.php 2007-02-19 22:30:27 UTC (rev 188) +++ pieforms-php5/trunk/src/pieform/elements/select.php 2007-02-19 23:17:52 UTC (rev 189) @@ -48,6 +48,9 @@ if (!empty($element['collapseifoneoption']) && isset($element['options']) && is_array($element['options']) && count($element['options']) == 1) { foreach ($element['options'] as $key => $value) { + if (is_array($value)) { + $value = $value['value']; + } $result = $value . '<input type="hidden" name="' . $element['name'] . '" value="' . $key . '">'; } return $result; @@ -79,7 +82,36 @@ else { $selected = ''; } - $result .= "\t<option value=\"" . Pieform::hsc($key) . "\"$selected>" . Pieform::hsc($value) . "</option>\n"; + + // Disable the option if necessary + if (is_array($value) && !empty($value['disabled'])) { + $disabled = ' disabled="disabled"'; + } + else { + $disabled = ''; + } + + // Add a label if necessary. None of the common browsers actually render + // this properly at the moment, but that may change in future. + if (is_array($value) && isset($value['label'])) { + $label = ' label="' . Pieform::hsc($value['label']) . '"'; + } + else { + $label = ''; + } + + // Get the value to display/put in the value attribute + if (is_array($value)) { + if (!isset($value['value'])) { + Pieform::info('No value set for option "' . $key . '" of select element "' . $element['name'] . '"'); + $value = ''; + } + else { + $value = $value['value']; + } + } + + $result .= "\t<option value=\"" . Pieform::hsc($key) . "\"{$selected}{$label}{$disabled}>" . Pieform::hsc($value) . "</option>\n"; } if (!$optionselected && !is_array($values) && $values !== null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-19 22:30:28
|
Revision: 188 http://svn.sourceforge.net/pieforms/?rev=188&view=rev Author: oracleshinoda Date: 2007-02-19 14:30:27 -0800 (Mon, 19 Feb 2007) Log Message: ----------- Added support for calling a help callback. Also added tbody tags to the renderer for IE's benefit Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2007-02-19 22:23:32 UTC (rev 187) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2007-02-19 22:30:27 UTC (rev 188) @@ -42,17 +42,17 @@ $closelegendpos = strpos($builtelement, '</legend>'); if ($closelegendpos !== false) { $closelegendpos += 9; - $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); + $builtelement = substr($builtelement, 0, $closelegendpos) . '<table><tbody>' . substr($builtelement, $closelegendpos); } else { $pos = strpos($builtelement, '>') + 1; - $builtelement = substr($builtelement, 0, $pos) . '<table>' . substr($builtelement, $pos); + $builtelement = substr($builtelement, 0, $pos) . '<table><tbody>' . substr($builtelement, $pos); } } else { - $builtelement = substr($builtelement, 0, 11) . '<table>' . substr($builtelement, 11); + $builtelement = substr($builtelement, 0, 11) . '<table><tbody>' . substr($builtelement, 11); } - $builtelement = substr($builtelement, 0, -12) . '</table></fieldset>'; + $builtelement = substr($builtelement, 0, -12) . '</tbody></table></fieldset>'; $result = "\t<tr>\n\t\t<td colspan=\"2\">"; $result .= $builtelement; @@ -83,7 +83,13 @@ // Contextual help if (!empty($rawelement['help'])) { - $result .= ' <span class="help"><a href="#" title="' . Pieform::hsc($rawelement['help']) . '">?</a></span>'; + $function = $form->get_property('helpcallback'); + if (function_exists($function)) { + $result .= $function($form, $rawelement); + } + else { + $result .= ' <span class="help"><a href="#" title="' . Pieform::hsc($rawelement['help']) . '">?</a></span>'; + } } $result .= "</td>\n\t</tr>\n"; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-19 22:23:37
|
Revision: 187 http://svn.sourceforge.net/pieforms/?rev=187&view=rev Author: oracleshinoda Date: 2007-02-19 14:23:32 -0800 (Mon, 19 Feb 2007) Log Message: ----------- Added support for defining a helpcallback that can be called for drawing the help. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/div.php Modified: pieforms-php5/trunk/src/pieform/renderers/div.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/div.php 2007-02-19 22:10:30 UTC (rev 186) +++ pieforms-php5/trunk/src/pieform/renderers/div.php 2007-02-19 22:23:32 UTC (rev 187) @@ -60,7 +60,13 @@ // Contextual help if (!empty($rawelement['help'])) { - $result .= ' <span class="help"><a href="#" title="' . Pieform::hsc($rawelement['help']) . '">?</a></span>'; + $function = $form->get_property('helpcallback'); + if (function_exists($function)) { + $result .= $function($form, $rawelement); + } + else { + $result .= ' <span class="help"><a href="#" title="' . Pieform::hsc($rawelement['help']) . '">?</a></span>'; + } } // Description - optional description of the element, or other note that should be visible This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-19 22:10:31
|
Revision: 186 http://svn.sourceforge.net/pieforms/?rev=186&view=rev Author: oracleshinoda Date: 2007-02-19 14:10:30 -0800 (Mon, 19 Feb 2007) Log Message: ----------- Merged oneline renderer fix from trunk Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform/renderers/oneline.php Modified: pieforms-php5/branches/0.2.0/src/pieform/renderers/oneline.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/renderers/oneline.php 2007-02-19 22:07:20 UTC (rev 185) +++ pieforms-php5/branches/0.2.0/src/pieform/renderers/oneline.php 2007-02-19 22:10:30 UTC (rev 186) @@ -70,4 +70,11 @@ return $result; } +function pieform_renderer_oneline_get_js($id) { + return <<<EOF +function {$id}_remove_all_errors () {} +function {$id}_set_error () {} +EOF; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-19 22:08:42
|
Revision: 185 http://svn.sourceforge.net/pieforms/?rev=185&view=rev Author: oracleshinoda Date: 2007-02-19 14:07:20 -0800 (Mon, 19 Feb 2007) Log Message: ----------- Added implementation of get_js for the oneline renderer, which allows it to be used as a jsform (although it doesn't show errors) Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/oneline.php Modified: pieforms-php5/trunk/src/pieform/renderers/oneline.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/oneline.php 2007-02-14 08:53:11 UTC (rev 184) +++ pieforms-php5/trunk/src/pieform/renderers/oneline.php 2007-02-19 22:07:20 UTC (rev 185) @@ -70,4 +70,11 @@ return $result; } +function pieform_renderer_oneline_get_js($id) { + return <<<EOF +function {$id}_remove_all_errors () {} +function {$id}_set_error () {} +EOF; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-14 08:53:16
|
Revision: 184 http://svn.sourceforge.net/pieforms/?rev=184&view=rev Author: oracleshinoda Date: 2007-02-14 00:53:11 -0800 (Wed, 14 Feb 2007) Log Message: ----------- Tagged the 0.2.1 release Added Paths: ----------- pieforms-php5/tags/0.2.1/ Copied: pieforms-php5/tags/0.2.1 (from rev 183, pieforms-php5/branches/0.2.0) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-14 08:37:03
|
Revision: 183 http://svn.sourceforge.net/pieforms/?rev=183&view=rev Author: oracleshinoda Date: 2007-02-14 00:37:02 -0800 (Wed, 14 Feb 2007) Log Message: ----------- Fixed the rules-apply-differently-depending-on-element thing. Not sure how this fix wasn't already checked in... Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform.php Modified: pieforms-php5/branches/0.2.0/src/pieform.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-11 09:43:21 UTC (rev 182) +++ pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-14 08:37:02 UTC (rev 183) @@ -831,7 +831,7 @@ if (!$this->get_error($element['name'])) { // See if this element has a function that describes // how this rule should apply to it - $function = 'pieform_element_' . $element['name'] . '_rule_' . $rule; + $function = 'pieform_element_' . $element['type'] . '_rule_' . $rule; if (!function_exists($function)) { // Try instead the default rule function $function = 'pieform_rule_' . $rule; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-11 09:43:21
|
Revision: 182 http://svn.sourceforge.net/pieforms/?rev=182&view=rev Author: oracleshinoda Date: 2007-02-11 01:43:21 -0800 (Sun, 11 Feb 2007) Log Message: ----------- Merged r180 to the stable 0.2.0 branch Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform/elements/select.php Modified: pieforms-php5/branches/0.2.0/src/pieform/elements/select.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/elements/select.php 2007-02-11 09:40:51 UTC (rev 181) +++ pieforms-php5/branches/0.2.0/src/pieform/elements/select.php 2007-02-11 09:43:21 UTC (rev 182) @@ -27,6 +27,10 @@ /** * Renders a dropdown list, including support for multiple choices. * + * @todo Currently, putting a junk defaultvalue/value for a multiple select + * does not trigger any kind of error, it should perhaps trigger a + * Pieform::info + * * @param Pieform $form The form to render the element for * @param array $element The element to render * @return string The HTML for the element @@ -36,7 +40,13 @@ $element['name'] .= '[]'; } - if (!empty($element['collapseifoneoption']) && count($element['options']) == 1) { + $optionsavailable = true; + if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { + $optionsavailable = false; + Pieform::info('Select elements should have at least one option'); + } + + if (!empty($element['collapseifoneoption']) && isset($element['options']) && is_array($element['options']) && count($element['options']) == 1) { foreach ($element['options'] as $key => $value) { $result = $value . '<input type="hidden" name="' . $element['name'] . '" value="' . $key . '">'; } @@ -47,32 +57,22 @@ . $form->element_attributes($element) . (!empty($element['multiple']) ? ' multiple="multiple"' : '') . ">\n"; - if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { - $result .= "\t<option></option>\n"; - Pieform::info('Select elements should have at least one option'); + if (!$optionsavailable) { + $result .= "\t<option></option>\n</select>"; + return $result; } - if (empty($element['multiple'])) { - $values = array($form->get_value($element)); - } - else { - if (isset($element['value'])) { - $values = (array) $element['value']; - } - // @todo use $global instead of $_POST - else if (isset($_POST[$element['name']])) { - $values = (array) $_POST[$element['name']]; - } - else if (isset($element['defaultvalue'])) { - $values = (array) $element['defaultvalue']; - } - else { - $values = array(); - } - } + $values = $form->get_value($element); $optionselected = false; foreach ($element['options'] as $key => $value) { - if (in_array($key, $values)) { + // Select the element if it's in the values or if there are no values + // and this is the first option + if ( + (!is_array($values) && $key == $values) + || + (is_array($values) && + (in_array($key, $values) + || (isset($values[0]) && $values[0] === null && !$optionselected)))) { $selected = ' selected="selected"'; $optionselected = true; } @@ -82,7 +82,7 @@ $result .= "\t<option value=\"" . Pieform::hsc($key) . "\"$selected>" . Pieform::hsc($value) . "</option>\n"; } - if (!$optionselected && $values) { + if (!$optionselected && !is_array($values) && $values !== null) { Pieform::info('Invalid value for select "' . $element['name'] .'"'); } @@ -96,4 +96,45 @@ return $element; } +function pieform_element_select_get_value(Pieform $form, $element) { + if (empty($element['multiple'])) { + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + if (isset($element['value'])) { + $values = (array) $element['value']; + } + else if (isset($global[$element['name']])) { + $values = (array) $global[$element['name']]; + } + else if (isset($element['defaultvalue'])) { + $values = (array) $element['defaultvalue']; + } + else { + $values = array(null); + } + + if (count($values) != 1) { + Pieform::info('The select element "' . $element['name'] . '" has ' + . 'more than one value, but has not been declared multiple'); + } + return $values[0]; + } + else { + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + if (isset($element['value'])) { + $values = (array) $element['value']; + } + else if (isset($global[$element['name']])) { + $values = (array) $global[$element['name']]; + } + else if (!$form->is_submitted() && isset($element['defaultvalue'])) { + $values = (array) $element['defaultvalue']; + } + else { + $values = array(); + } + } + + return $values; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-11 09:40:52
|
Revision: 181 http://svn.sourceforge.net/pieforms/?rev=181&view=rev Author: oracleshinoda Date: 2007-02-11 01:40:51 -0800 (Sun, 11 Feb 2007) Log Message: ----------- Fixed SF bug #1635520 - select elements no longer require a default value. Also fixed some other minor annoyances around how the select element behaves. Now the only thing that is not done is triggering a notice if a multiselect does not have a correct value Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/select.php Modified: pieforms-php5/trunk/src/pieform/elements/select.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/select.php 2007-02-11 05:39:21 UTC (rev 180) +++ pieforms-php5/trunk/src/pieform/elements/select.php 2007-02-11 09:40:51 UTC (rev 181) @@ -27,6 +27,10 @@ /** * Renders a dropdown list, including support for multiple choices. * + * @todo Currently, putting a junk defaultvalue/value for a multiple select + * does not trigger any kind of error, it should perhaps trigger a + * Pieform::info + * * @param Pieform $form The form to render the element for * @param array $element The element to render * @return string The HTML for the element @@ -36,7 +40,13 @@ $element['name'] .= '[]'; } - if (!empty($element['collapseifoneoption']) && count($element['options']) == 1) { + $optionsavailable = true; + if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { + $optionsavailable = false; + Pieform::info('Select elements should have at least one option'); + } + + if (!empty($element['collapseifoneoption']) && isset($element['options']) && is_array($element['options']) && count($element['options']) == 1) { foreach ($element['options'] as $key => $value) { $result = $value . '<input type="hidden" name="' . $element['name'] . '" value="' . $key . '">'; } @@ -47,32 +57,22 @@ . $form->element_attributes($element) . (!empty($element['multiple']) ? ' multiple="multiple"' : '') . ">\n"; - if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { - $result .= "\t<option></option>\n"; - Pieform::info('Select elements should have at least one option'); + if (!$optionsavailable) { + $result .= "\t<option></option>\n</select>"; + return $result; } - if (empty($element['multiple'])) { - $values = array($form->get_value($element)); - } - else { - if (isset($element['value'])) { - $values = (array) $element['value']; - } - // @todo use $global instead of $_POST - else if (isset($_POST[$element['name']])) { - $values = (array) $_POST[$element['name']]; - } - else if (isset($element['defaultvalue'])) { - $values = (array) $element['defaultvalue']; - } - else { - $values = array(); - } - } + $values = $form->get_value($element); $optionselected = false; foreach ($element['options'] as $key => $value) { - if (in_array($key, $values)) { + // Select the element if it's in the values or if there are no values + // and this is the first option + if ( + (!is_array($values) && $key == $values) + || + (is_array($values) && + (in_array($key, $values) + || (isset($values[0]) && $values[0] === null && !$optionselected)))) { $selected = ' selected="selected"'; $optionselected = true; } @@ -82,7 +82,7 @@ $result .= "\t<option value=\"" . Pieform::hsc($key) . "\"$selected>" . Pieform::hsc($value) . "</option>\n"; } - if (!$optionselected && $values) { + if (!$optionselected && !is_array($values) && $values !== null) { Pieform::info('Invalid value for select "' . $element['name'] .'"'); } @@ -96,4 +96,45 @@ return $element; } +function pieform_element_select_get_value(Pieform $form, $element) { + if (empty($element['multiple'])) { + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + if (isset($element['value'])) { + $values = (array) $element['value']; + } + else if (isset($global[$element['name']])) { + $values = (array) $global[$element['name']]; + } + else if (isset($element['defaultvalue'])) { + $values = (array) $element['defaultvalue']; + } + else { + $values = array(null); + } + + if (count($values) != 1) { + Pieform::info('The select element "' . $element['name'] . '" has ' + . 'more than one value, but has not been declared multiple'); + } + return $values[0]; + } + else { + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + if (isset($element['value'])) { + $values = (array) $element['value']; + } + else if (isset($global[$element['name']])) { + $values = (array) $global[$element['name']]; + } + else if (!$form->is_submitted() && isset($element['defaultvalue'])) { + $values = (array) $element['defaultvalue']; + } + else { + $values = array(); + } + } + + return $values; +} + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-11 05:39:21
|
Revision: 180 http://svn.sourceforge.net/pieforms/?rev=180&view=rev Author: oracleshinoda Date: 2007-02-10 21:39:21 -0800 (Sat, 10 Feb 2007) Log Message: ----------- Merged changes from revision 179 to branch Revision Links: -------------- http://svn.sourceforge.net/pieforms/?rev=179&view=rev Modified Paths: -------------- pieforms-php5/branches/0.2.0/CHANGELOG pieforms-php5/branches/0.2.0/INSTALL pieforms-php5/branches/0.2.0/README Modified: pieforms-php5/branches/0.2.0/CHANGELOG =================================================================== --- pieforms-php5/branches/0.2.0/CHANGELOG 2007-02-11 05:37:20 UTC (rev 179) +++ pieforms-php5/branches/0.2.0/CHANGELOG 2007-02-11 05:39:21 UTC (rev 180) @@ -1,7 +1,7 @@ Pieforms - Advanced web forms made easy Nigel McNie - http://nigel.mcnie.name/ - (C) 2006 Catalyst IT Ltd - http://catalyst.net.nz/ + (C) 2006, 2007 Catalyst IT Ltd - http://catalyst.net.nz/ For a list of changes between versions, please see the sourceforge release notes and changes for the release you have downloaded. This contains both a Modified: pieforms-php5/branches/0.2.0/INSTALL =================================================================== --- pieforms-php5/branches/0.2.0/INSTALL 2007-02-11 05:37:20 UTC (rev 179) +++ pieforms-php5/branches/0.2.0/INSTALL 2007-02-11 05:39:21 UTC (rev 180) @@ -1,7 +1,7 @@ Pieforms - Advanced web forms made easy Nigel McNie - http://nigel.mcnie.name/ - (C) 2006 Catalyst IT Ltd - http://catalyst.net.nz/ + (C) 2006, 2007 Catalyst IT Ltd - http://catalyst.net.nz/ Requirements ------------ Modified: pieforms-php5/branches/0.2.0/README =================================================================== --- pieforms-php5/branches/0.2.0/README 2007-02-11 05:37:20 UTC (rev 179) +++ pieforms-php5/branches/0.2.0/README 2007-02-11 05:39:21 UTC (rev 180) @@ -1,7 +1,7 @@ Pieforms - Advanced web forms made easy Nigel McNie - http://nigel.mcnie.name/ - (C) 2006 Catalyst IT Ltd - http://catalyst.net.nz/ + (C) 2006, 2007 Catalyst IT Ltd - http://catalyst.net.nz/ For installation instructions, please see the INSTALL file in this folder @@ -9,7 +9,7 @@ -------------- Pieforms provides a simple, unified way to create, validate and process web -forms all with a common look and field. It supports many more types of form +forms all with a common look and feel. It supports many more types of form controls (elements) than the standard HTML controls, for example date pickers and ajax comboboxes. In addition, each element can have pluggable rules applied to it, and the elements can be rendered inside custom containers, @@ -55,7 +55,7 @@ Pieforms is licensed under the GNU GPL. For more information, please see the COPYING file that comes with this package. -Pieforms is copyright (C) 2006 Catalyst IT Ltd. +Pieforms is copyright (C) 2006, 2007 Catalyst IT Ltd. Pieforms includes parts of MochiKit [1], which is required for the AJAX post functionality. MochiKit is dual licensed under the MIT license or Academic @@ -65,11 +65,12 @@ functionality, if the json extension for PHP is not installed or enabled. Services_JSON is licensed under the BSD license. -Pieforms includes the free version of the dynarch javascript calendar, which +Pieforms includes the free version of the dynarch javascript calendar [3], which is required for the 'calendar' element to function properly. The calendar is licensed under the LGPL. [1] http://mochikit.com/ [2] http://pear.php.net/pepr/pepr-proposal-show.php?id=198 +[3] http://www.dynarch.com/projects/calendar/ -- Nigel McNie <ni...@ca...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-11 05:37:25
|
Revision: 179 http://svn.sourceforge.net/pieforms/?rev=179&view=rev Author: oracleshinoda Date: 2007-02-10 21:37:20 -0800 (Sat, 10 Feb 2007) Log Message: ----------- Corrected copyright years, one typo, and linked to the JS calendar Modified Paths: -------------- pieforms-php5/trunk/CHANGELOG pieforms-php5/trunk/INSTALL pieforms-php5/trunk/README Modified: pieforms-php5/trunk/CHANGELOG =================================================================== --- pieforms-php5/trunk/CHANGELOG 2007-02-09 08:38:01 UTC (rev 178) +++ pieforms-php5/trunk/CHANGELOG 2007-02-11 05:37:20 UTC (rev 179) @@ -1,7 +1,7 @@ Pieforms - Advanced web forms made easy Nigel McNie - http://nigel.mcnie.name/ - (C) 2006 Catalyst IT Ltd - http://catalyst.net.nz/ + (C) 2006, 2007 Catalyst IT Ltd - http://catalyst.net.nz/ For a list of changes between versions, please see the sourceforge release notes and changes for the release you have downloaded. This contains both a Modified: pieforms-php5/trunk/INSTALL =================================================================== --- pieforms-php5/trunk/INSTALL 2007-02-09 08:38:01 UTC (rev 178) +++ pieforms-php5/trunk/INSTALL 2007-02-11 05:37:20 UTC (rev 179) @@ -1,7 +1,7 @@ Pieforms - Advanced web forms made easy Nigel McNie - http://nigel.mcnie.name/ - (C) 2006 Catalyst IT Ltd - http://catalyst.net.nz/ + (C) 2006, 2007 Catalyst IT Ltd - http://catalyst.net.nz/ Requirements ------------ Modified: pieforms-php5/trunk/README =================================================================== --- pieforms-php5/trunk/README 2007-02-09 08:38:01 UTC (rev 178) +++ pieforms-php5/trunk/README 2007-02-11 05:37:20 UTC (rev 179) @@ -1,7 +1,7 @@ Pieforms - Advanced web forms made easy Nigel McNie - http://nigel.mcnie.name/ - (C) 2006 Catalyst IT Ltd - http://catalyst.net.nz/ + (C) 2006, 2007 Catalyst IT Ltd - http://catalyst.net.nz/ For installation instructions, please see the INSTALL file in this folder @@ -9,7 +9,7 @@ -------------- Pieforms provides a simple, unified way to create, validate and process web -forms all with a common look and field. It supports many more types of form +forms all with a common look and feel. It supports many more types of form controls (elements) than the standard HTML controls, for example date pickers and ajax comboboxes. In addition, each element can have pluggable rules applied to it, and the elements can be rendered inside custom containers, @@ -55,7 +55,7 @@ Pieforms is licensed under the GNU GPL. For more information, please see the COPYING file that comes with this package. -Pieforms is copyright (C) 2006 Catalyst IT Ltd. +Pieforms is copyright (C) 2006, 2007 Catalyst IT Ltd. Pieforms includes parts of MochiKit [1], which is required for the AJAX post functionality. MochiKit is dual licensed under the MIT license or Academic @@ -65,11 +65,12 @@ functionality, if the json extension for PHP is not installed or enabled. Services_JSON is licensed under the BSD license. -Pieforms includes the free version of the dynarch javascript calendar, which +Pieforms includes the free version of the dynarch javascript calendar [3], which is required for the 'calendar' element to function properly. The calendar is licensed under the LGPL. [1] http://mochikit.com/ [2] http://pear.php.net/pepr/pepr-proposal-show.php?id=198 +[3] http://www.dynarch.com/projects/calendar/ -- Nigel McNie <ni...@ca...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-09 08:38:04
|
Revision: 178 http://svn.sourceforge.net/pieforms/?rev=178&view=rev Author: oracleshinoda Date: 2007-02-09 00:38:01 -0800 (Fri, 09 Feb 2007) Log Message: ----------- Merged commit 177 from trunk Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform.php Modified: pieforms-php5/branches/0.2.0/src/pieform.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-09 07:50:51 UTC (rev 177) +++ pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-09 08:38:01 UTC (rev 178) @@ -890,8 +890,6 @@ * without the breakage. */ private function submit_js() { - $strprocessingform = get_string('processingform'); - $result = <<<EOF connect($('{$this->name}'), 'onsubmit', function(e) { if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-09 07:50:51
|
Revision: 177 http://svn.sourceforge.net/pieforms/?rev=177&view=rev Author: oracleshinoda Date: 2007-02-08 23:50:51 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Removed call to get_string that is causing problems Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-02-04 23:00:03 UTC (rev 176) +++ pieforms-php5/trunk/src/pieform.php 2007-02-09 07:50:51 UTC (rev 177) @@ -890,8 +890,6 @@ * without the breakage. */ private function submit_js() { - $strprocessingform = get_string('processingform'); - $result = <<<EOF connect($('{$this->name}'), 'onsubmit', function(e) { if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-04 23:00:06
|
Revision: 176 http://svn.sourceforge.net/pieforms/?rev=176&view=rev Author: oracleshinoda Date: 2007-02-04 15:00:03 -0800 (Sun, 04 Feb 2007) Log Message: ----------- Merged fixes from trunk Modified Paths: -------------- pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php pieforms-php5/branches/0.2.0/src/pieform.php Added Paths: ----------- pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php Copied: pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php (from rev 171, pieforms-php5/trunk/src/pieform/elements/bytes.php) =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php (rev 0) +++ pieforms-php5/branches/0.2.0/src/pieform/elements/bytes.php 2007-02-04 23:00:03 UTC (rev 176) @@ -0,0 +1,151 @@ +<?php +/** + * This program is part of Pieforms + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * @package pieform + * @subpackage element + * @author Martyn Smith <ma...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * + */ + +/** + * Provides a size chooser, with a text box for a number and a + * select box to choose the units, in bytes, kilobytes, or megabytes + * + * @param Pieform $form The form to render the element for + * @param array $element The element to render + * @return string The HTML for the element + */ +function pieform_element_bytes(Pieform $form, $element) { + $formname = $form->get_name(); + $result = ''; + $name = $element['name']; + if (!isset($element['defaultvalue'])) { + $element['defaultvalue'] = null; + } + + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + + // Get the value of the element for rendering. + if (isset($element['value'])) { + $bytes = $element['value']; + $values = pieform_element_bytes_get_bytes_from_bytes($element['value']); + } + else if (isset($global[$element['name']]) + && isset($global[$element['name'] . '_units'])) { + $values = array('number' => $global[$element['name']], + 'units' => $global[$element['name'] . '_units']); + $bytes = $values['number'] * pieform_element_bytes_in($values['units']); + } + else if (isset($element['defaultvalue'])) { + $bytes = $element['defaultvalue']; + $values = pieform_element_bytes_get_bytes_from_bytes($bytes); + } + else { + $values = array('number' => '0', 'units' => 'bytes'); + $bytes = 0; + } + + // @todo probably create with an actual input element, as tabindex doesn't work here for one thing + // Same with the select. And do the events using mochikit signal instead of dom events + $numberinput = '<input'; + $numberinput .= ' type="text" size="8" name="' . $name . '"'; + $numberinput .= ' id="' . $formname . '_' . $name . '" value="' . $values['number'] . '" tabindex="' . $element['tabindex'] . '"'; + $numberinput .= (isset($element['error']) ? ' class="error"' : '') . ">\n"; + + $uselect = '<select onchange="' . $name . '_change()" '; + $uselect .= 'name="' . $name . '_units" id="' . $formname . '_' . $name . '_units"' . ' tabindex="' . $element['tabindex'] . "\">\n"; + foreach (pieform_element_bytes_get_bytes_units() as $u) { + $uselect .= "\t<option value=\"$u\"" . (($values['units'] == $u) ? ' selected="selected"' : '') . '>' + . $form->i18n('element', 'bytes', $u, $element) . "</option>\n"; + } + $uselect .= "</select>\n"; + + return $numberinput . $uselect; +} + +/** + * Gets the value of the expiry element and converts it to a time in seconds. + * + * @param Pieform $form The form the element is attached to + * @param array $element The element to get the value for + * @return int The number of seconds until expiry + */ +function pieform_element_bytes_get_value(Pieform $form, $element) { + $name = $element['name']; + + $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; + $unit = $global[$name . '_units']; + $allunits = pieform_element_bytes_get_bytes_units(); + $number = $global[$name]; + + if (!is_numeric($number)) { + $form->set_error($name, $form->i18n('element', 'bytes', 'invalidvalue', $element)); + } + + if (!in_array($unit,$allunits) || $number < 0) { + return null; + } + return $number * pieform_element_bytes_in($unit); +} + +function pieform_element_bytes_in($units) { + switch ($units) { + case 'megabytes': + return 1048576; + break; + case 'kilobytes': + return 1024; + break; + default: + return 1; + break; + }; +} + +function pieform_element_bytes_i18n() { + return array( + 'en.utf8' => array( + 'bytes' => 'Bytes', + 'kilobytes' => 'Kilobytes', + 'megabytes' => 'Megabytes', + 'invalidvalue' => 'Value must be a number', + ), + ); +} + +function pieform_element_bytes_get_bytes_units() { + return array('bytes', 'kilobytes', 'megabytes'); +} + +function pieform_element_bytes_get_bytes_from_bytes($bytes) { + if ($bytes == null) { + return array('number' => '0', 'units' => 'bytes'); + } + + foreach (array('megabytes', 'kilobytes') as $units) { + if ( $bytes > pieform_element_bytes_in($units) ) { + return array('number' => $bytes / pieform_element_bytes_in($units) , 'units' => $units); + } + } + + return array('number' => $bytes, 'units' => 'bytes'); +} + +?> Modified: pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php 2007-02-04 22:40:21 UTC (rev 175) +++ pieforms-php5/branches/0.2.0/src/pieform/elements/fieldset.php 2007-02-04 23:00:03 UTC (rev 176) @@ -34,8 +34,11 @@ */ function pieform_element_fieldset(Pieform $form, $element) { $result = "\n<fieldset"; - if (!empty($element['collapsable'])) { - $classes = array('collapsable'); + if (!empty($element['collapsible'])) { + if (!isset($element['legend']) || $element['legend'] === '') { + Pieform::info('Collapsible fieldsets should have a legend so they can be toggled'); + } + $classes = array('collapsible'); // Work out whether any of the children have errors on them $error = false; foreach ($element['elements'] as $subelement) { @@ -52,7 +55,7 @@ $result .= ">\n"; if (isset($element['legend'])) { $result .= '<legend'; - if (!empty($element['collapsable'])) { + if (!empty($element['collapsible'])) { $id = substr(md5(microtime()), 0, 4); $result .= ' id="' . $id . '">'; $result .= '<script type="text/javascript">'; Modified: pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php 2007-02-04 22:40:21 UTC (rev 175) +++ pieforms-php5/branches/0.2.0/src/pieform/renderers/table.php 2007-02-04 23:00:03 UTC (rev 176) @@ -39,8 +39,15 @@ if ($rawelement['type'] == 'fieldset') { // Add table tags to the build element, to preserve HTML compliance if (0 === strpos($builtelement, "\n<fieldset")) { - $closelegendpos = strpos($builtelement, '</legend>') + 9; - $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); + $closelegendpos = strpos($builtelement, '</legend>'); + if ($closelegendpos !== false) { + $closelegendpos += 9; + $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); + } + else { + $pos = strpos($builtelement, '>') + 1; + $builtelement = substr($builtelement, 0, $pos) . '<table>' . substr($builtelement, $pos); + } } else { $builtelement = substr($builtelement, 0, 11) . '<table>' . substr($builtelement, 11); Modified: pieforms-php5/branches/0.2.0/src/pieform.php =================================================================== --- pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-04 22:40:21 UTC (rev 175) +++ pieforms-php5/branches/0.2.0/src/pieform.php 2007-02-04 23:00:03 UTC (rev 176) @@ -325,6 +325,22 @@ throw new PieformException('Forms must have a list of elements'); } + // Rename all the keys to have nice compliant names + // @todo: + // - This isn't done for elements inside fieldsets + // - There's no easy way for other things do do all this preprocessing if they + // need. It should be a method so that other things (like multirecord) + // can use it. + $elements = array(); + foreach ($this->data['elements'] as $name => $element) { + $newname = preg_replace('/[^a-zA-Z0-9_]/', '_', $name); + if (isset($elements[$name])) { + throw new PieformException('Element "' . $name . '" has a dangerous name that interferes with another element'); + } + $elements[$newname] = $element; + } + $this->data['elements'] = $elements; + // Remove elements to ignore foreach ($this->data['elements'] as $name => $element) { if (isset($element['type']) && $element['type'] == 'fieldset') { @@ -867,6 +883,12 @@ return $result; } + /** + * Builds the javascript for submitting the form. Note that the iframe is + * not hidden with display: none, as safari/konqueror/ns6 ignore things with + * display: none. Positioning it absolute and 'hidden' has the same effect + * without the breakage. + */ private function submit_js() { $strprocessingform = get_string('processingform'); @@ -885,9 +907,9 @@ if (!iframe) { iframe = createDOM('iframe', { 'name': '{$this->name}_iframe', - 'id' : '{$this->name}_iframe' + 'id' : '{$this->name}_iframe', + 'style': 'position: absolute; visibility: hidden;' }); - hideElement(iframe); insertSiblingNodesAfter($('{$this->name}'), iframe); window.pieformHandler_{$this->name} = function(data) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-04 22:40:21
|
Revision: 175 http://svn.sourceforge.net/pieforms/?rev=175&view=rev Author: oracleshinoda Date: 2007-02-04 14:40:21 -0800 (Sun, 04 Feb 2007) Log Message: ----------- Handle having no legend better Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/table.php Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2007-02-04 22:39:59 UTC (rev 174) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2007-02-04 22:40:21 UTC (rev 175) @@ -39,8 +39,15 @@ if ($rawelement['type'] == 'fieldset') { // Add table tags to the build element, to preserve HTML compliance if (0 === strpos($builtelement, "\n<fieldset")) { - $closelegendpos = strpos($builtelement, '</legend>') + 9; - $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); + $closelegendpos = strpos($builtelement, '</legend>'); + if ($closelegendpos !== false) { + $closelegendpos += 9; + $builtelement = substr($builtelement, 0, $closelegendpos) . '<table>' . substr($builtelement, $closelegendpos); + } + else { + $pos = strpos($builtelement, '>') + 1; + $builtelement = substr($builtelement, 0, $pos) . '<table>' . substr($builtelement, $pos); + } } else { $builtelement = substr($builtelement, 0, 11) . '<table>' . substr($builtelement, 11); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-04 22:39:59
|
Revision: 174 http://svn.sourceforge.net/pieforms/?rev=174&view=rev Author: oracleshinoda Date: 2007-02-04 14:39:59 -0800 (Sun, 04 Feb 2007) Log Message: ----------- Fixed the form submission support under safari, by hiding the iframe instead of removing it. Try to normalise the names of the elements if possible (although this does not check inside fieldsets and needs some work) Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-02-04 22:38:38 UTC (rev 173) +++ pieforms-php5/trunk/src/pieform.php 2007-02-04 22:39:59 UTC (rev 174) @@ -325,6 +325,22 @@ throw new PieformException('Forms must have a list of elements'); } + // Rename all the keys to have nice compliant names + // @todo: + // - This isn't done for elements inside fieldsets + // - There's no easy way for other things do do all this preprocessing if they + // need. It should be a method so that other things (like multirecord) + // can use it. + $elements = array(); + foreach ($this->data['elements'] as $name => $element) { + $newname = preg_replace('/[^a-zA-Z0-9_]/', '_', $name); + if (isset($elements[$name])) { + throw new PieformException('Element "' . $name . '" has a dangerous name that interferes with another element'); + } + $elements[$newname] = $element; + } + $this->data['elements'] = $elements; + // Remove elements to ignore foreach ($this->data['elements'] as $name => $element) { if (isset($element['type']) && $element['type'] == 'fieldset') { @@ -867,6 +883,12 @@ return $result; } + /** + * Builds the javascript for submitting the form. Note that the iframe is + * not hidden with display: none, as safari/konqueror/ns6 ignore things with + * display: none. Positioning it absolute and 'hidden' has the same effect + * without the breakage. + */ private function submit_js() { $strprocessingform = get_string('processingform'); @@ -885,9 +907,9 @@ if (!iframe) { iframe = createDOM('iframe', { 'name': '{$this->name}_iframe', - 'id' : '{$this->name}_iframe' + 'id' : '{$this->name}_iframe', + 'style': 'position: absolute; visibility: hidden;' }); - hideElement(iframe); insertSiblingNodesAfter($('{$this->name}'), iframe); window.pieformHandler_{$this->name} = function(data) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |