pieforms-commit Mailing List for Pieforms (Page 3)
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...> - 2008-01-03 08:57:47
|
Revision: 273 http://pieforms.svn.sourceforge.net/pieforms/?rev=273&view=rev Author: oracleshinoda Date: 2008-01-03 00:57:53 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Make sure the 'resizable' flag is still respected for textareas. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/textarea.php Modified: pieforms-php5/trunk/src/pieform/elements/textarea.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/textarea.php 2008-01-03 08:57:17 UTC (rev 272) +++ pieforms-php5/trunk/src/pieform/elements/textarea.php 2008-01-03 08:57:53 UTC (rev 273) @@ -62,9 +62,9 @@ if (!empty($element['resizable'])) { $element['class'] = (isset($element['class']) && $element['class']) ? $element['class'] . ' resizable' : 'resizable'; + $_PIEFORM_TEXTAREAS[] = array('formname' => $form->get_name(), 'elementname' => $form->get_name() . '_' . $element['id']); } - $_PIEFORM_TEXTAREAS[] = array('formname' => $form->get_name(), 'elementname' => $form->get_name() . '_' . $element['id']); return '<textarea' . (($rows) ? ' rows="' . $rows . '"' : '') . (($cols) ? ' cols="' . $cols . '"' : '') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2008-01-03 08:57:13
|
Revision: 272 http://pieforms.svn.sourceforge.net/pieforms/?rev=272&view=rev Author: oracleshinoda Date: 2008-01-03 00:57:17 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Moved the textarea javascript into its own plugin file which is now loaded only if forms on the page have a textarea. Added Paths: ----------- pieforms-php5/trunk/src/static/core/elements/ pieforms-php5/trunk/src/static/core/elements/textarea.js Added: pieforms-php5/trunk/src/static/core/elements/textarea.js =================================================================== --- pieforms-php5/trunk/src/static/core/elements/textarea.js (rev 0) +++ pieforms-php5/trunk/src/static/core/elements/textarea.js 2008-01-03 08:57:17 UTC (rev 272) @@ -0,0 +1,141 @@ +/** + * Pieforms: Advanced web forms made easy + * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz) + * Copyright (C) 2006 Drupal (http://www.drupal.org) + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + * + * @package pieform + * @subpackage static + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006 Drupal http://www.drupal.org + * + */ + +/** + * Retrieves the absolute position of an element on the screen + * This function (C) 2006 Drupal + */ +function absolutePosition(el) {//{{{ + var sLeft = 0, sTop = 0; + var isDiv = /^div$/i.test(el.tagName); + if (isDiv && el.scrollLeft) { + sLeft = el.scrollLeft; + } + if (isDiv && el.scrollTop) { + sTop = el.scrollTop; + } + var r = { x: el.offsetLeft - sLeft, y: el.offsetTop - sTop }; + if (el.offsetParent) { + var tmp = absolutePosition(el.offsetParent); + r.x += tmp.x; + r.y += tmp.y; + } + return r; +}//}}} + +/** + * This class based on Drupal's textArea class, which is (C) 2006 Drupal + * + * Provides a 'grippie' for resizing a textarea vertically. + */ +function PieformTextarea(element) {//{{{ + var self = this; + + this.element = element; + this.parent = this.element.parentNode; + this.dimensions = getElementDimensions(element); + + // Prepare wrapper + this.wrapper = DIV({'class':'resizable-textarea'}); + insertSiblingNodesBefore(this.element, this.wrapper); + + // Add grippie and measure it + this.grippie = DIV({'class': 'grippie'}); + appendChildNodes(this.wrapper, this.grippie); + this.grippie.dimensions = getElementDimensions(this.grippie); + + // Set wrapper and textarea dimensions + setElementDimensions(this.wrapper, {'h': this.dimensions.h + this.grippie.dimensions.h + 1, 'w': this.dimensions.w}); + setStyle(this.element, { + 'margin-bottom': '0', + 'width': '100%', + 'height': this.dimensions.h + 'px' + }); + + // Wrap textarea + removeElement(this.element); + insertSiblingNodesBefore(this.grippie, this.element); + + // Measure difference between desired and actual textarea dimensions to account for padding/borders + this.widthOffset = getElementDimensions(this.wrapper).w - this.dimensions.w; + + // Make the grippie line up in various browsers + if (window.opera) { + setStyle(this.grippie, {'margin-right': '4px'}); + } + if (document.all && !window.opera) { + this.grippie.style.width = '100%'; + this.grippie.style.paddingLeft = '2px'; + setStyle(this.grippie, { + 'padding-left': '2px' + }); + } + this.element.style.MozBoxSizing = 'border-box'; + + this.heightOffset = absolutePosition(this.grippie).y - absolutePosition(this.element).y - this.dimensions.h; + + + this.handleDrag = function (e) {//{{{ + // Get coordinates relative to text area + var pos = absolutePosition(this.element); + var y = e.mouse().client.y - pos.y; + + // Set new height + var height = Math.max(32, y - this.dragOffset - this.heightOffset); + setStyle(this.wrapper, {'height': height + this.grippie.dimensions.h + 1 + 'px'}); + setStyle(this.element, {'height': height + 'px'}); + + // Avoid text selection + e.stop(); + }//}}} + + this.endDrag = function (e) {//{{{ + disconnect(this.mouseMoveHandler); + disconnect(this.mouseUpHandler); + document.isDragging = false; + }//}}} + + this.beginDrag = function(e) {//{{{ + if (document.isDragging) { + return; + } + document.isDragging = true; + + self.mouseMoveHandler = connect(document, 'onmousemove', self, 'handleDrag'); + self.mouseUpHandler = connect(document, 'onmouseup', self, 'endDrag'); + + // Store drag offset from grippie top + var pos = absolutePosition(this.grippie); + this.dragOffset = e.mouse().client.y - pos.y; + + // Process + this.handleDrag(e); + }//}}} + + connect(this.grippie, 'onmousedown', self, 'beginDrag'); +}//}}} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2008-01-03 08:56:39
|
Revision: 271 http://pieforms.svn.sourceforge.net/pieforms/?rev=271&view=rev Author: oracleshinoda Date: 2008-01-03 00:56:44 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Added a headdata function to get javascript required to initialise resizable textareas. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/textarea.php Modified: pieforms-php5/trunk/src/pieform/elements/textarea.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/textarea.php 2008-01-03 08:56:18 UTC (rev 270) +++ pieforms-php5/trunk/src/pieform/elements/textarea.php 2008-01-03 08:56:44 UTC (rev 271) @@ -24,6 +24,9 @@ * */ +// TODO: plugins as classes... +$_PIEFORM_TEXTAREAS = array(); + /** * Renders a basic HTML <textarea> element. * @@ -32,6 +35,7 @@ * @return string The HTML for the element */ function pieform_element_textarea(Pieform $form, $element) {/*{{{*/ + global $_PIEFORM_TEXTAREAS; $rows = $cols = $style = ''; if (isset($element['height'])) { $style .= 'height:' . $element['height'] . ';'; @@ -59,6 +63,8 @@ if (!empty($element['resizable'])) { $element['class'] = (isset($element['class']) && $element['class']) ? $element['class'] . ' resizable' : 'resizable'; } + + $_PIEFORM_TEXTAREAS[] = array('formname' => $form->get_name(), 'elementname' => $form->get_name() . '_' . $element['id']); return '<textarea' . (($rows) ? ' rows="' . $rows . '"' : '') . (($cols) ? ' cols="' . $cols . '"' : '') @@ -83,4 +89,16 @@ return ''; }/*}}}*/ +function pieform_element_textarea_get_headdata() {/*{{{*/ + global $_PIEFORM_TEXTAREAS; + + $result = '<script type="text/javascript">'; + $result .= "PieformManager.loadPlugin('element', 'textarea');\n"; + foreach ($_PIEFORM_TEXTAREAS as $textarea) { + $result .= 'PieformManager.connect("onload", "'.$textarea['formname'].'", function(){new PieformTextarea($("' . $textarea['elementname'] . '"));});' . "\n"; + } + $result .= "</script>"; + return array($result); +}/*}}}*/ + ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2008-01-03 08:56:15
|
Revision: 270 http://pieforms.svn.sourceforge.net/pieforms/?rev=270&view=rev Author: oracleshinoda Date: 2008-01-03 00:56:18 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Added a new PieformManager class, to centralise some operations that are the same across any pieform. Now focus is handled from this class. It has the ability to load plugin javascript files, which should contribute to keeping javascript out of the HTML documents somewhat - now it can all be safely constrained to the <head>. It also has a signal/slot mechanism for two events - form finished loading, and form submitted. Added foldmarkers to the Pieform class also. Modified Paths: -------------- pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2008-01-03 08:55:52 UTC (rev 269) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2008-01-03 08:56:18 UTC (rev 270) @@ -26,23 +26,118 @@ window.pieformHandlers = {}; /** + * Handles things that work the same across all pieforms, such as plugin + * management and events + */ +function PieformManager() {//{{{ + var self = this; + + this.init = function() {//{{{ + self.connect('onload', null, self.setFocus); + self.signal('onload', null); + }//}}} + + /** + * When called, ensures the focus is set correctly for all pieforms on the + * page + */ + this.setFocus = function() {//{{{ + var check = getElementsByTagAndClassName('form', 'pieform'); + var formsWithError = filter(function(i) { return hasElementClass(i, 'error'); }, check); + if (formsWithError.length > 0) { + check = formsWithError; + } + forEach(check, function(form) { + var element = getFirstElementByTagAndClassName(null, 'autofocus', form); + if (element && typeof(element.focus) == 'function') { + element.focus(); + throw MochiKit.Iter.StopIteration; + } + }); + }//}}} + + /** + * Loads a javascript plugin file + */ + this.loadPlugin = function(type, name) {//{{{ + if (type != 'element' && type != 'renderer' && type != 'rule') { + throw 'Plugin type ' + type + ' is not valid'; + } + if (typeof(self.loadCache[type][name]) != 'undefined') { + return; + } + + var script = createDOM('script', { + 'type': 'text/javascript', + 'src' : self.pieformPath + type + 's/' + name + '.js' + }); + + appendChildNodes(self.head, script); + self.loadCache[type][name] = 1; + }//}}} + + /** + * Registers an observer for a given event type + */ + this.connect = function(slot, form, callback) {//{{{ + if (typeof(self.observers[slot]) == 'undefined') { + throw 'Slot ' + slot + ' does not exist'; + } + self.observers[slot].push({'form': form, 'callback': callback}); + }//}}} + + this.signal = function(slot, form) {//{{{ + forEach(self.observers[slot], function(observer) { + if (form == null || observer.form == null || form == observer['form']) { + observer.callback(form); + } + }); + }//}}} + + this.head = getFirstElementByTagAndClassName('head'); + + if (typeof(pieformPath) == 'string') { + this.pieformPath = pieformPath; + if (pieformPath.substr(pieformPath.length - 1, 1) != '/') { + this.pieformPath += '/'; + } + } + else { + this.pieformPath = ''; + } + + this.loadCache = {'element': {}, 'renderer': {}, 'rule': {}}; + + this.observers = { + 'onload' : [], // when elements are loaded + 'onsubmit': [] // when a form is submitted + }; + + addLoadEvent(self.init); +}//}}} + +PieformManager = new PieformManager(); + + +/** * Handles the javascript side of pieforms - submitting the form via a hidden * iframe and dealing with the result */ -function Pieform(data) { +function Pieform(data) {//{{{ var self = this; - this.init = function() { + this.init = function() {//{{{ connect(self.data.name, 'onsubmit', self.processForm); self.connectSubmitButtons(); - } + }//}}} - this.processForm = function(e) { + this.processForm = function(e) {//{{{ // HACK: save any tinyMCE elements on the page. // TODO: allow elements to export javascript to run at certain times - // like now, when the form is being submitted if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } + PieformManager.signal('onsubmit', self.data.name); // Call the presubmit callback, if there is one if (typeof(self.data.preSubmitCallback) == 'string' @@ -77,13 +172,23 @@ var tmp = DIV(); tmp.innerHTML = data.replaceHTML; + + // Work out whether the new form tag has the error class on it, for + // updating the form in the document + if (hasElementClass(tmp.childNodes[0], 'error')) { + addElementClass(self.data.name, 'error'); + } + else { + removeElementClass(self.data.name, 'error'); + } + // The first child node is the form tag. We replace the children of // the current form tag with the new children. This prevents // javascript references being lost replaceChildNodes($(self.data.name), tmp.childNodes[0].childNodes); self.connectSubmitButtons(); - pieformSetFocus(); + PieformManager.signal('onload', self.data.name); if (data.returnCode == 0) { // Call the defined success callback, if there is one @@ -121,9 +226,9 @@ window[self.data.postSubmitCallback]($(self.data.name), self.clickedButton, e); } } - } + }//}}} - this.setupIframe = function() { + this.setupIframe = function() {//{{{ var iframeName = self.data.name + '_iframe'; if ($(iframeName)) { self.iframe = $(iframeName); @@ -136,16 +241,16 @@ }); insertSiblingNodesAfter(self.data.name, self.iframe); } - } + }//}}} - this.connectSubmitButtons = function() { + this.connectSubmitButtons = function() {//{{{ forEach(self.data.submitButtons, function(buttonName) { var btn = $(self.data.name + '_' + buttonName); if (btn) { connect(btn, 'onclick', function() { self.clickedButton = this; }); } }); - } + }//}}} // A reference to the iframe that submissions are made through this.iframe = null; @@ -157,144 +262,5 @@ this.data = data; addLoadEvent(self.init); -} +}//}}} -function pieformSetFocus() { - var check = getElementsByTagAndClassName('form', 'pieform'); - var formsWithError = filter(function(i) { return hasElementClass(i, 'error'); }, check); - if (formsWithError.length > 0) { - check = formsWithError; - } - forEach(check, function(form) { - var element = getFirstElementByTagAndClassName(null, 'autofocus', form); - if (element && typeof(element.focus) == 'function') { - element.focus(); - throw MochiKit.Iter.StopIteration; - } - }); -} -addLoadEvent(pieformSetFocus); - -// The resizable textarea code is based on the code from Drupal (http://drupal.org/) - -/** - * Retrieves the absolute position of an element on the screen - * This function (C) 2006 Drupal - */ -function absolutePosition(el) { - var sLeft = 0, sTop = 0; - var isDiv = /^div$/i.test(el.tagName); - if (isDiv && el.scrollLeft) { - sLeft = el.scrollLeft; - } - if (isDiv && el.scrollTop) { - sTop = el.scrollTop; - } - var r = { x: el.offsetLeft - sLeft, y: el.offsetTop - sTop }; - if (el.offsetParent) { - var tmp = absolutePosition(el.offsetParent); - r.x += tmp.x; - r.y += tmp.y; - } - return r; -} - -addLoadEvent(function() { - forEach(getElementsByTagAndClassName('form', 'pieform'), function(form) { - forEach(getElementsByTagAndClassName('textarea', 'resizable', form), function (textarea) { - new TextArea(textarea); - }); - }); -}); - -/** - * This class based on Drupal's textArea class, which is (C) 2006 Drupal - * - * Provides a 'grippie' for resizing a textarea vertically. - */ -function TextArea(element) { - var self = this; - - this.element = element; - this.parent = this.element.parentNode; - this.dimensions = getElementDimensions(element); - - // Prepare wrapper - this.wrapper = DIV({'class':'resizable-textarea'}); - insertSiblingNodesBefore(this.element, this.wrapper); - - // Add grippie and measure it - this.grippie = DIV({'class': 'grippie'}); - appendChildNodes(this.wrapper, this.grippie); - this.grippie.dimensions = getElementDimensions(this.grippie); - - // Set wrapper and textarea dimensions - setElementDimensions(this.wrapper, {'h': this.dimensions.h + this.grippie.dimensions.h + 1, 'w': this.dimensions.w}); - setStyle(this.element, { - 'margin-bottom': '0', - 'width': '100%', - 'height': this.dimensions.h + 'px' - }); - - // Wrap textarea - removeElement(this.element); - insertSiblingNodesBefore(this.grippie, this.element); - - // Measure difference between desired and actual textarea dimensions to account for padding/borders - this.widthOffset = getElementDimensions(this.wrapper).w - this.dimensions.w; - - // Make the grippie line up in various browsers - if (window.opera) { - setStyle(this.grippie, {'margin-right': '4px'}); - } - if (document.all && !window.opera) { - this.grippie.style.width = '100%'; - this.grippie.style.paddingLeft = '2px'; - setStyle(this.grippie, { - 'padding-left': '2px' - }); - } - this.element.style.MozBoxSizing = 'border-box'; - - this.heightOffset = absolutePosition(this.grippie).y - absolutePosition(this.element).y - this.dimensions.h; - - - this.handleDrag = function (e) { - // Get coordinates relative to text area - var pos = absolutePosition(this.element); - var y = e.mouse().client.y - pos.y; - - // Set new height - var height = Math.max(32, y - this.dragOffset - this.heightOffset); - setStyle(this.wrapper, {'height': height + this.grippie.dimensions.h + 1 + 'px'}); - setStyle(this.element, {'height': height + 'px'}); - - // Avoid text selection - e.stop(); - } - - this.endDrag = function (e) { - disconnect(this.mouseMoveHandler); - disconnect(this.mouseUpHandler); - document.isDragging = false; - } - - this.beginDrag = function(e) { - if (document.isDragging) { - return; - } - document.isDragging = true; - - self.mouseMoveHandler = connect(document, 'onmousemove', self, 'handleDrag'); - self.mouseUpHandler = connect(document, 'onmouseup', self, 'endDrag'); - - // Store drag offset from grippie top - var pos = absolutePosition(this.grippie); - this.dragOffset = e.mouse().client.y - pos.y; - - // Process - this.handleDrag(e); - } - - connect(this.grippie, 'onmousedown', self, 'beginDrag'); -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2008-01-03 08:55:49
|
Revision: 269 http://pieforms.svn.sourceforge.net/pieforms/?rev=269&view=rev Author: oracleshinoda Date: 2008-01-03 00:55:52 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Now pieform_get_headdata will output the tags for the pieforms.js file. Another configuration parameter - jsincludepath - has been added to assist with this, but that configuration parameter should be set statically rather than for each form. When it comes time for the head data to be retrieved, the last form created has its jsincludepath used, above all others. This doesn't matter too much when you use pieform_configure. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 12:16:36 UTC (rev 268) +++ pieforms-php5/trunk/src/pieform.php 2008-01-03 08:55:52 UTC (rev 269) @@ -1308,6 +1308,11 @@ // supported in less browsers. Most modern browsers should be fine) 'jsform' => false, + // The URL where pieforms.js and other related pieforms javascript + // files can be accessed. Best specified as an absolute path in + // pieform_configure() + 'jsincludepath' => '', + // The javascript function called before submission of a form // (regardless of whether the form is a jsform) 'presubmitcallback' => '', @@ -1445,6 +1450,12 @@ } } + // TODO: jsincludepath should be independent of ANY form + array_unshift($htmlelements, '<script type="text/javascript" src="' + . Pieform::hsc($form->get_property('jsincludepath')) . 'pieforms.js"></script>'); + array_unshift($htmlelements, '<script type="text/javascript">pieformPath = "' + . Pieform::hsc($form->get_property('jsincludepath')) . '";</script>'); + return array_unique($htmlelements); }/*}}}*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:16:36
|
Revision: 268 http://pieforms.svn.sourceforge.net/pieforms/?rev=268&view=rev Author: oracleshinoda Date: 2007-12-31 04:16:36 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Now pieforms.js will focus things that require focusing on page load, and when forms are submitted it will update what is focused. This works even when there is more than one form on the page - the code will work out the correct element to focus. Modified Paths: -------------- pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:16:11 UTC (rev 267) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:16:36 UTC (rev 268) @@ -83,6 +83,7 @@ replaceChildNodes($(self.data.name), tmp.childNodes[0].childNodes); self.connectSubmitButtons(); + pieformSetFocus(); if (data.returnCode == 0) { // Call the defined success callback, if there is one @@ -158,6 +159,22 @@ addLoadEvent(self.init); } +function pieformSetFocus() { + var check = getElementsByTagAndClassName('form', 'pieform'); + var formsWithError = filter(function(i) { return hasElementClass(i, 'error'); }, check); + if (formsWithError.length > 0) { + check = formsWithError; + } + forEach(check, function(form) { + var element = getFirstElementByTagAndClassName(null, 'autofocus', form); + if (element && typeof(element.focus) == 'function') { + element.focus(); + throw MochiKit.Iter.StopIteration; + } + }); +} +addLoadEvent(pieformSetFocus); + // The resizable textarea code is based on the code from Drupal (http://drupal.org/) /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:16:09
|
Revision: 267 http://pieforms.svn.sourceforge.net/pieforms/?rev=267&view=rev Author: oracleshinoda Date: 2007-12-31 04:16:11 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Add the 'error' class to the form tag if the form has errors on it. This helps with autofocus right now, as the autofocus code can 'focus its efforts', so to speak, on forms with errors on them first. But it might also help application developers who are trying to style forms with errors on them. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 12:15:51 UTC (rev 266) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 12:16:11 UTC (rev 267) @@ -521,7 +521,11 @@ * @return string */ public function get_form_tag() {/*{{{*/ - $result = '<form class="pieform"'; + $result = '<form class="pieform'; + if ($this->has_errors()) { + $result .= ' error'; + } + $result .= '"'; foreach (array('name', 'method', 'action') as $attribute) { $result .= ' ' . $attribute . '="' . $this->data[$attribute] . '"'; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:15:51
|
Revision: 266 http://pieforms.svn.sourceforge.net/pieforms/?rev=266&view=rev Author: oracleshinoda Date: 2007-12-31 04:15:51 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Make the support for putting the name in the element itself work again. Was previously broken when I messed around with the constructor, I've only just picked up the mistake. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 12:15:25 UTC (rev 265) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 12:15:51 UTC (rev 266) @@ -237,6 +237,12 @@ // Get references to all the elements in the form, excluding fieldsets foreach ($this->data['elements'] as $name => &$element) { + // The name can be in the element itself. This is compatibility for + // the perl version + if (isset($element['name'])) { + $name = $element['name']; + } + if (isset($element['type']) && $element['type'] == 'fieldset') { // Load the fieldset plugin as we know this form has one now $this->include_plugin('element', 'fieldset'); @@ -245,13 +251,19 @@ } foreach ($element['elements'] as $subname => &$subelement) { + if (isset($subelement['name'])) { + $subname = $subelement['name']; + } $this->elementrefs[$subname] = &$subelement; + $subelement['name'] = $subname; } unset($subelement); } else { $this->elementrefs[$name] = &$element; } + + $element['name'] = $name; } unset($element); @@ -301,11 +313,6 @@ // Now we know what type the element is, we can load the plugin for it $this->include_plugin('element', $element['type']); - // The name can be in the element itself. This is compatibility for the perl version - if (isset($element['name'])) { - $name = $element['name']; - } - // All elements should have at least the title key set if (!isset($element['title'])) { $element['title'] = ''; @@ -352,7 +359,6 @@ // All elements inherit the form tabindex $element['tabindex'] = $this->data['tabindex']; } - $element['name'] = $name; } unset($element); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:15:21
|
Revision: 265 http://pieforms.svn.sourceforge.net/pieforms/?rev=265&view=rev Author: oracleshinoda Date: 2007-12-31 04:15:25 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Only wire up the submit buttons if they're actually present. They might not be if the application has defined the replaceHTML for the form to be something else that doesn't have the buttons in it. Modified Paths: -------------- pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:14:53 UTC (rev 264) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:15:25 UTC (rev 265) @@ -139,7 +139,10 @@ this.connectSubmitButtons = function() { forEach(self.data.submitButtons, function(buttonName) { - connect(self.data.name + '_' + buttonName, 'onclick', function() { self.clickedButton = this; }); + var btn = $(self.data.name + '_' + buttonName); + if (btn) { + connect(btn, 'onclick', function() { self.clickedButton = this; }); + } }); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:14:48
|
Revision: 264 http://pieforms.svn.sourceforge.net/pieforms/?rev=264&view=rev Author: oracleshinoda Date: 2007-12-31 04:14:53 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Ensure that, once the form has been submitted once, the new submit buttons are wired up again so the one that is clicked next time can be detected. Modified Paths: -------------- pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:14:23 UTC (rev 263) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:14:53 UTC (rev 264) @@ -35,9 +35,7 @@ this.init = function() { connect(self.data.name, 'onsubmit', self.processForm); - forEach(self.data.submitButtons, function(buttonName) { - connect(self.data.name + '_' + buttonName, 'onclick', function() { self.clickedButton = this; }); - }); + self.connectSubmitButtons(); } this.processForm = function(e) { @@ -84,6 +82,8 @@ // javascript references being lost replaceChildNodes($(self.data.name), tmp.childNodes[0].childNodes); + self.connectSubmitButtons(); + if (data.returnCode == 0) { // Call the defined success callback, if there is one if (typeof(self.data.jsSuccessCallback) == 'string' @@ -137,6 +137,12 @@ } } + this.connectSubmitButtons = function() { + forEach(self.data.submitButtons, function(buttonName) { + connect(self.data.name + '_' + buttonName, 'onclick', function() { self.clickedButton = this; }); + }); + } + // A reference to the iframe that submissions are made through this.iframe = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:14:19
|
Revision: 263 http://pieforms.svn.sourceforge.net/pieforms/?rev=263&view=rev Author: oracleshinoda Date: 2007-12-31 04:14:23 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Removing a debugging alert box. Modified Paths: -------------- pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:13:56 UTC (rev 262) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:14:23 UTC (rev 263) @@ -73,7 +73,6 @@ window.pieformHandlers[self.data.name] = function(data) { // If canceling the form, redirect away if (data.returnCode == -2) { - alert('redirecting to ' + data.goto); window.location = data.goto; return; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:13:53
|
Revision: 262 http://pieforms.svn.sourceforge.net/pieforms/?rev=262&view=rev Author: oracleshinoda Date: 2007-12-31 04:13:56 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Add proper detection for if a form is submitted by javascript. This means forms can degrade gracefully if javascript is disabled. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 12:13:15 UTC (rev 261) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 12:13:56 UTC (rev 262) @@ -147,6 +147,14 @@ * @var bool */ private $submitted = false; + + /** + * Whether the form has been submitted by javasccript. Available through + * the {@link submitted_by_js} method. + * + * @var bool + */ + private $submitted_by_js = false; /*}}}*/ @@ -353,6 +361,13 @@ if ($this->data['validate'] && isset($global['pieform_' . $this->name] )) { if ($this->data['submit']) { $this->submitted = true; + + // If the hidden value the JS code inserts into the form is + // present, then the form was submitted by JS + if (!empty($global['pieform_jssubmission'])) { + $this->submitted_by_js = true; + } + // Check if the form has been cancelled if ($this->data['iscancellable']) { foreach ($global as $key => $value) { @@ -368,7 +383,7 @@ if (!isset($element['goto'])) { throw new PieformException('Cancel element "' . $element['name'] . '" has no page to go to'); } - if ($this->data['jsform']) { + if ($this->submitted_by_js) { $this->json_reply(PIEFORM_CANCEL, array('goto' => $element['goto']), false); } header('HTTP/1.1 303 See Other'); @@ -436,7 +451,7 @@ } // If the form has been submitted by javascript, return json - if ($this->data['jsform']) { + if ($this->submitted_by_js) { // TODO: get error messages in a 'third person' type form to // use here maybe? Would have to work for non js forms too. See // the TODO file @@ -486,6 +501,15 @@ }/*}}}*/ /** + * Returns whether the form has been submitted by javascript + * + * @return bool + */ + public function submitted_by_js() {/*{{{*/ + return $this->submitted_by_js; + }/*}}}*/ + + /** * Returns the HTML for the <form...> tag * * @return string Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:13:15 UTC (rev 261) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 12:13:56 UTC (rev 262) @@ -62,6 +62,14 @@ self.setupIframe(); $(self.data.name).target = self.data.name + '_iframe'; + appendChildNodes(self.data.name, + INPUT({ + 'type': 'hidden', + 'name': 'pieform_jssubmission', + 'value': 1 + }) + ); + window.pieformHandlers[self.data.name] = function(data) { // If canceling the form, redirect away if (data.returnCode == -2) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 12:13:11
|
Revision: 261 http://pieforms.svn.sourceforge.net/pieforms/?rev=261&view=rev Author: oracleshinoda Date: 2007-12-31 04:13:15 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Tidy up a couple of comments. Make the javascript for the form output itself on one line. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 09:05:31 UTC (rev 260) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 12:13:15 UTC (rev 261) @@ -622,14 +622,17 @@ } } - // Output the javascript to wire things up, but only if it is needed. The two cases where it is needed is when: + // Output the javascript to wire things up, but only if it is needed. + // The two cases where it is needed is when: // 1) The form is a JS form that hasn't been submitted yet. When the // form has been submitted the javascript from the first page load is // still active in the documente // 2) The form is NOT a JS form, but has a presubmitcallback if (($this->data['jsform'] && !$this->submitted) || (!$this->data['jsform'] && $this->data['presubmitcallback'])) { - $result .= '<script type="text/javascript">'; + // Establish which buttons in the form are submit buttons. This is + // used to detect which button was pressed to cause the form + // submission $submitbuttons = array(); foreach ($this->elementrefs as $element) { if (!empty($element['submitelement'])) { @@ -648,8 +651,7 @@ 'globalJsErrorCallback' => $this->data['globaljserrorcallback'], 'postSubmitCallback' => $this->data['postsubmitcallback'], )); - $result .= "new Pieform($data);\n"; - $result .= "</script>\n"; + $result .= "<script type=\"text/javascript\">new Pieform($data);</script>\n"; } return $result; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 09:05:32
|
Revision: 260 http://pieforms.svn.sourceforge.net/pieforms/?rev=260&view=rev Author: oracleshinoda Date: 2007-12-31 01:05:31 -0800 (Mon, 31 Dec 2007) Log Message: ----------- Moved the javascript for handling jsform submission into pieforms.js, and made it work by AHAH. The major gain of this is that any form can display itself again when an error occurs in 100% the same way, regardless of whether the form is a jsform or not. The renderers don't have to provide javascript to describe how to insert error messages anymore either. The code is simpler and faster this way. So good benefits all around! Furthermore, I found that you can unset() a reference safely (i.e., it won't be unset everwhere else - only the reference will die). This is really handy for those foreach loops that take values by reference - you can unset them at the end of the loop and then know you can use the variable name again safely without random breakage happening later. Used this knowledge to fix one such 'interesting' bug that was occuring after jsform submission, where the last element in the form would be replaced by the second-to-last element. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/renderers/div.php pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php pieforms-php5/trunk/src/pieform/renderers/oneline.php pieforms-php5/trunk/src/pieform/renderers/table.php pieforms-php5/trunk/src/pieform.php pieforms-php5/trunk/src/static/core/pieforms.js Modified: pieforms-php5/trunk/src/pieform/renderers/div.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/div.php 2007-12-31 02:03:42 UTC (rev 259) +++ pieforms-php5/trunk/src/pieform/renderers/div.php 2007-12-31 09:05:31 UTC (rev 260) @@ -68,26 +68,4 @@ return $result; }/*}}}*/ - -function pieform_renderer_div_get_js($id) {/*{{{*/ - $result = <<<EOF -// Given a message and form element name, should set an error on the element -function {$id}_set_error(message, element) { - element = '{$id}_' + element; - addElementClass(element + '_container', 'error'); - addElementClass(element, 'error'); - insertSiblingNodesAfter(element + '_container', DIV({'class': 'errmsg'}, message)); -} -function {$id}_remove_all_errors() { - forEach(getElementsByTagAndClassName('DIV', 'errmsg', '{$id}'), function(div) { - removeElement(div); - }); - forEach(getElementsByTagAndClassName(null, 'error', '{$id}'), function(div) { - removeElementClass(div, 'error'); - }); -} -EOF; - return $result; -}/*}}}*/ - ?> Modified: pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2007-12-31 02:03:42 UTC (rev 259) +++ pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2007-12-31 09:05:31 UTC (rev 260) @@ -43,43 +43,6 @@ $formrenderermct->set_form($form); }/*}}}*/ -function pieform_renderer_multicolumntable_get_js($id) {/*{{{*/ - return <<<EOF -function {$id}_set_error (message, element) { - element = '{$id}_' + element; - var parentRow = $(element + '_container').parentNode; - var nextRow = parentRow.nextSibling; - if (!(nextRow && hasElementClass(nextRow, 'errorRow'))) { - var errorRow = TR({'class': 'errorRow'}); - log(parentRow.cells.length); - for (var i = 0; i < parentRow.cells.length; i++) { - var attrs = null; - if (parentRow.cells[i].id) { - attrs = { - 'id': parentRow.cells[i].id.replace(/_container$/, '_error'), - 'class': 'error' - }; - } - appendChildNodes(errorRow, TD(attrs)); - } - insertSiblingNodesAfter($(element + '_container').parentNode, errorRow); - } - - appendChildNodes(element + '_error', message); - addElementClass(element, 'error'); - addElementClass( element + '_container', 'error'); -} -function {$id}_remove_all_errors() { - forEach(getElementsByTagAndClassName('TR', 'errorRow', '{$id}'), function(row) { - removeElement(row); - }); - forEach(getElementsByTagAndClassName(null, 'error', '{$id}'), function(item) { - removeElementClass(item, 'error'); - }); -} -EOF; -}/*}}}*/ - function pieform_renderer_multicolumntable_header() {/*{{{*/ global $formrenderermct; $formrenderermct = new FormRendererMultiColumnTable(); Modified: pieforms-php5/trunk/src/pieform/renderers/oneline.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/oneline.php 2007-12-31 02:03:42 UTC (rev 259) +++ pieforms-php5/trunk/src/pieform/renderers/oneline.php 2007-12-31 09:05:31 UTC (rev 260) @@ -70,11 +70,4 @@ return $result; }/*}}}*/ -function pieform_renderer_oneline_get_js($id) {/*{{{*/ - return <<<EOF -function {$id}_remove_all_errors () {} -function {$id}_set_error () {} -EOF; -}/*}}}*/ - ?> Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2007-12-31 02:03:42 UTC (rev 259) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2007-12-31 09:05:31 UTC (rev 260) @@ -102,26 +102,4 @@ return "</tbody></table>\n"; }/*}}}*/ -function pieform_renderer_table_get_js($id) {/*{{{*/ - $result = <<<EOF -function {$id}_set_error(message, element) { - element = $('{$id}_' + element + '_container'); - var container = getFirstElementByTagAndClassName('TD', null, element); - addElementClass(container, 'error'); - addElementClass(container.firstChild, 'error'); - insertSiblingNodesAfter(element, TR(null, TD({'colspan': 2, 'class': 'errmsg'}, message))); -} -function {$id}_remove_all_errors() { - forEach(getElementsByTagAndClassName('TD', 'errmsg', $('$id')), function(item) { - removeElement(item.parentNode); - }); - forEach(getElementsByTagAndClassName('TD', 'error', $('$id')), function(item) { - removeElementClass(item, 'error'); - removeElementClass(item.firstChild, 'error'); - }); -} -EOF; - return $result; -}/*}}}*/ - ?> Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 02:03:42 UTC (rev 259) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 09:05:31 UTC (rev 260) @@ -228,22 +228,24 @@ } // Get references to all the elements in the form, excluding fieldsets - foreach ($this->data['elements'] as $name => &$_element) { - if (isset($_element['type']) && $_element['type'] == 'fieldset') { + foreach ($this->data['elements'] as $name => &$element) { + if (isset($element['type']) && $element['type'] == 'fieldset') { // Load the fieldset plugin as we know this form has one now $this->include_plugin('element', 'fieldset'); if ($this->get_property('template')) { self::info("Your form '$this->name' has a fieldset, but is using a template. Fieldsets make no sense when using templates"); } - foreach ($_element['elements'] as $subname => &$_subelement) { - $this->elementrefs[$subname] = &$_subelement; + foreach ($element['elements'] as $subname => &$subelement) { + $this->elementrefs[$subname] = &$subelement; } + unset($subelement); } else { - $this->elementrefs[$name] = &$_element; + $this->elementrefs[$name] = &$element; } } + unset($element); // Check that all elements have names compliant to PHP's variable naming policy // (otherwise things get messy later) @@ -344,6 +346,7 @@ } $element['name'] = $name; } + unset($element); // Check if the form was submitted, and if so, validate and process it $global = ($this->data['method'] == 'get') ? $_GET: $_POST; @@ -366,7 +369,7 @@ throw new PieformException('Cancel element "' . $element['name'] . '" has no page to go to'); } if ($this->data['jsform']) { - $this->json_reply(PIEFORM_CANCEL, $element['goto']); + $this->json_reply(PIEFORM_CANCEL, array('goto' => $element['goto']), false); } header('HTTP/1.1 303 See Other'); header('Location:' . $element['goto']); @@ -434,13 +437,16 @@ // If the form has been submitted by javascript, return json if ($this->data['jsform']) { - $errors = $this->get_errors(); - $json = array(); - foreach ($errors as $element) { - $json[$element['name']] = $element['error']; - } + // TODO: get error messages in a 'third person' type form to + // use here maybe? Would have to work for non js forms too. See + // the TODO file + //$errors = $this->get_errors(); + //$json = array(); + //foreach ($errors as $element) { + // $json[$element['name']] = $element['error']; + //} $message = $this->get_property('jserrormessage'); - $this->json_reply(PIEFORM_ERR, array('message' => $message, 'errors' => $json)); + $this->json_reply(PIEFORM_ERR, array('message' => $message)); } } }/*}}}*/ @@ -614,23 +620,36 @@ if ($outputformtags) { $result .= "</form>\n"; } + } - if ($this->data['jsform'] || $this->data['presubmitcallback']) { - $result .= '<script type="text/javascript">'; - if ($outputformtags) { - $result .= "\n" . $this->whichbutton_js(); + // Output the javascript to wire things up, but only if it is needed. The two cases where it is needed is when: + // 1) The form is a JS form that hasn't been submitted yet. When the + // form has been submitted the javascript from the first page load is + // still active in the documente + // 2) The form is NOT a JS form, but has a presubmitcallback + if (($this->data['jsform'] && !$this->submitted) + || (!$this->data['jsform'] && $this->data['presubmitcallback'])) { + $result .= '<script type="text/javascript">'; + $submitbuttons = array(); + foreach ($this->elementrefs as $element) { + if (!empty($element['submitelement'])) { + // TODO: might have to deal with cancel elements here too + $submitbuttons[] = $element['name']; } } - if ($this->data['jsform']) { - $result .= $this->submit_js(); - } - else if ($this->data['presubmitcallback'] && $outputformtags) { - $result .= 'connect(\'' . $this->name . '\', \'onsubmit\', ' - . 'function() { ' . $this->data['presubmitcallback'] . "('{$this->name}', {$this->name}_btn); });"; - } - if ($this->data['jsform'] || $this->data['presubmitcallback']) { - $result .= "\n</script>\n"; - } + + $data = json_encode(array( + 'name' => $this->name, + 'jsForm' => $this->data['jsform'], + 'submitButtons' => $submitbuttons, + 'preSubmitCallback' => $this->data['presubmitcallback'], + 'jsSuccessCallback' => $this->data['jssuccesscallback'], + 'jsErrorCallback' => $this->data['jserrorcallback'], + 'globalJsErrorCallback' => $this->data['globaljserrorcallback'], + 'postSubmitCallback' => $this->data['postsubmitcallback'], + )); + $result .= "new Pieform($data);\n"; + $result .= "</script>\n"; } return $result; @@ -788,149 +807,40 @@ } }/*}}}*/ - private function whichbutton_js() {/*{{{*/ - $result = "var {$this->name}_btn = null;\n"; - - $connecteventadded = false; - foreach ($this->elementrefs as $element) { - if (!empty($element['submitelement'])) { - if (!$connecteventadded) { - $result .= "addLoadEvent(function() {\n"; - $connecteventadded = true; - } - if (!empty($element['cancelelement'])) { - $cancelstr = 'cancel_'; - } - else { - $cancelstr = ''; - } - $result .= " connect($('{$cancelstr}{$this->name}_{$element['name']}'), 'onclick', function() { {$this->name}_btn = '{$cancelstr}{$this->name}_{$element['name']}'; });\n"; - } - } - if ($connecteventadded) { - $result .= "});\n"; - } - - 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. + * Sends a message back to a jsform. + * + * The message can contain almost any data, although how it is used is up to + * the javascript callbacks. The message must contain a return code (the + * first parameter of this method. + * + * - The return code of the result. Either one of the PIEFORM_OK, + * PIEFORM_ERR or PIEFORM_CANCEL codes, or a custom error code at the + * choice of the application using pieforms + * - A message. This is just a string that can be used as a status message, + * e.g. 'Form failed submission' + * - HTML to replace the form with. By default, the form is built and used, + * but for example, you could replace the form with a "thank you" message + * after successful submission if you want */ - private function submit_js() {/*{{{*/ - $result = <<<EOF -connect($('{$this->name}'), 'onsubmit', function(e) { - if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } - -EOF; - if (!empty($this->data['presubmitcallback'])) { - $result .= " {$this->data['presubmitcallback']}('{$this->name}', {$this->name}_btn);\n"; + public function json_reply($returncode, $data=array(), $replacehtml=null) {/*{{{*/ + if (is_string($data)) { + $data = array( + 'message' => $data, + ); } - $result .= <<<EOF - - var iframe = $('{$this->name}_iframe'); - $('{$this->name}').target = '{$this->name}_iframe'; - if (!iframe) { - iframe = createDOM('iframe', { - 'name': '{$this->name}_iframe', - 'id' : '{$this->name}_iframe', - 'style': 'position: absolute; visibility: hidden;' - }); - insertSiblingNodesAfter($('{$this->name}'), iframe); - - window.pieformHandler_{$this->name} = function(data) { - -EOF; - if (isset($this->data['processingstopcallback'])) { - $result .= " {$this->data['processingstopcallback']}('{$this->name}', {$this->name}_btn);\n"; + $data['returnCode'] = intval($returncode); + if ($replacehtml === null) { + $data['replaceHTML'] = $this->build(); } - - $result .= <<<EOF - evalJSONRequest(data); - if (data.returnCode == 0) { - {$this->name}_remove_all_errors(); - // The request completed successfully - -EOF; - if (!empty($this->data['jssuccesscallback'])) { - $result .= " {$this->data['jssuccesscallback']}('{$this->name}', data);\n"; + else if (is_string($replacehtml)) { + $data['replaceHTML'] = $replacehtml; } - $result .= <<<EOF - } - else { - if (data.returnCode == -2) { - window.location = data.message; - return; - } - - {$this->name}_remove_all_errors(); - if (data.message.errors) { - for (error in data.message.errors) { - {$this->name}_set_error(data.message.errors[error], error); - } - // @todo only output when fieldsets are present - forEach(getElementsByTagAndClassName('fieldset', 'collapsed', '{$this->name}'), function(fieldset) { - if (getFirstElementByTagAndClassName(null, 'error', fieldset)) { - removeElementClass(fieldset, 'collapsed'); - } - }); - } - - if (data.returnCode == -1) { - -EOF; - if (!empty($this->data['jserrorcallback'])) { - $result .= " {$this->data['jserrorcallback']}('{$this->name}', data);\n"; - } - $result .= <<<EOF - } - else { - -EOF; - if (!empty($this->data['globaljserrorcallback'])) { - $result .= " {$this->data['globaljserrorcallback']}('{$this->name}', data);\n"; - } - else { - $result .= " alert('Developer: got error code ' + data.returnCode - + ', either fix your form to not use this code or define a global js error handler');\n"; - } - $result .= <<<EOF - } - } - -EOF; - if (!empty($this->data['postsubmitcallback'])) { - $result .= " {$this->data['postsubmitcallback']}('{$this->name}', {$this->name}_btn);\n"; - } - - $result .= <<<EOF - {$this->name}_btn = null; - } - } - -EOF; - $result .= "});\n\n"; - $function = 'pieform_renderer_' . $this->data['renderer'] . '_get_js'; - if (!function_exists($function)) { - throw new PieformException('No renderer message function "' . $function . '"'); - } - - return $result . $function($this->name); - }/*}}}*/ - - public function json_reply($returncode, $message=null) {/*{{{*/ - $data = array( - 'returnCode' => intval($returncode), - 'message' => $message - ); $result = json_encode($data); echo <<<EOF -<html><head><script type="text/javascript">function sendResult() { parent.pieformHandler_{$this->name}($result); }</script></head><body onload="sendResult(); "></body></html> +<html><head><script type="text/javascript">function sendResult() { parent.pieformHandlers["{$this->name}"]($result); }</script></head><body onload="sendResult(); "></body></html> EOF; exit; }/*}}}*/ Modified: pieforms-php5/trunk/src/static/core/pieforms.js =================================================================== --- pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 02:03:42 UTC (rev 259) +++ pieforms-php5/trunk/src/static/core/pieforms.js 2007-12-31 09:05:31 UTC (rev 260) @@ -1,11 +1,147 @@ /** - * Pieforms core javascript - * Author: Nigel McNie - * (C) 2006 Nigel McNie - * Released under the GNU GPL, see the COPYING file - * @todo pack this, provide a source version. Same with MochiKit + * Pieforms: Advanced web forms made easy + * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz) + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + * + * @package pieform + * @subpackage static + * @author Nigel McNie <ni...@ca...> + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz + * */ +window.pieformHandlers = {}; + +/** + * Handles the javascript side of pieforms - submitting the form via a hidden + * iframe and dealing with the result + */ +function Pieform(data) { + var self = this; + + this.init = function() { + connect(self.data.name, 'onsubmit', self.processForm); + + forEach(self.data.submitButtons, function(buttonName) { + connect(self.data.name + '_' + buttonName, 'onclick', function() { self.clickedButton = this; }); + }); + } + + this.processForm = function(e) { + // HACK: save any tinyMCE elements on the page. + // TODO: allow elements to export javascript to run at certain times - + // like now, when the form is being submitted + if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } + + // Call the presubmit callback, if there is one + if (typeof(self.data.preSubmitCallback) == 'string' + && self.data.preSubmitCallback != "") { + window[self.data.preSubmitCallback]($(self.data.name), self.clickedButton, e); + } + + // If the form actually isn't a jsform - i.e. only a presubmithandler + // was defined - we stop here + if (!self.data.jsForm) { + return; + } + + // Ensure the iframe exists and make sure the form targets it + self.setupIframe(); + $(self.data.name).target = self.data.name + '_iframe'; + + window.pieformHandlers[self.data.name] = function(data) { + // If canceling the form, redirect away + if (data.returnCode == -2) { + alert('redirecting to ' + data.goto); + window.location = data.goto; + return; + } + + var tmp = DIV(); + tmp.innerHTML = data.replaceHTML; + // The first child node is the form tag. We replace the children of + // the current form tag with the new children. This prevents + // javascript references being lost + replaceChildNodes($(self.data.name), tmp.childNodes[0].childNodes); + + if (data.returnCode == 0) { + // Call the defined success callback, if there is one + if (typeof(self.data.jsSuccessCallback) == 'string' + && self.data.jsSuccessCallback != "") { + window[self.data.jsSuccessCallback]($(self.data.name), data); + } + else { + // TODO: work out what I'm going to do here... + if (typeof(data.message) == 'string' && data.message != '') { + alert(data.message); + } + } + } + else if (data.returnCode == -1) { + if (typeof(self.data.jsErrorCallback) == 'string' + && self.data.jsErrorCallback != '') { + window[self.data.jsErrorCallback]($(self.data.name), data); + } + } + else if (typeof(self.data.globalJsErrorCallback) == 'string' + && self.data.globalJsErrorCallback != '') { + window[self.data.globalJsErrorCallback]($(self.data.name), data); + } + else { + alert('Developer: got error code ' + data.returnCode + + ', either fix your form to not use this code or define ' + + 'a global js error handler'); + } + + // The post submit callback (for if the form succeeds or fails, but + // not for if it cancels) + if (typeof(self.data.postSubmitCallback) == 'string' + && self.data.postSubmitCallback != '') { + window[self.data.postSubmitCallback]($(self.data.name), self.clickedButton, e); + } + } + } + + this.setupIframe = function() { + var iframeName = self.data.name + '_iframe'; + if ($(iframeName)) { + self.iframe = $(iframeName); + } + else { + self.iframe = createDOM('iframe', { + 'name': iframeName, + 'id' : iframeName, + 'style': 'position: absolute; visibility: hidden;' + }); + insertSiblingNodesAfter(self.data.name, self.iframe); + } + } + + // A reference to the iframe that submissions are made through + this.iframe = null; + + // The button that was clicked to trigger the form submission + this.clickedButton = null; + + // Form configuration data passed from PHP + this.data = data; + + addLoadEvent(self.init); +} + // The resizable textarea code is based on the code from Drupal (http://drupal.org/) /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 02:03:36
|
Revision: 259 http://pieforms.svn.sourceforge.net/pieforms/?rev=259&view=rev Author: oracleshinoda Date: 2007-12-30 18:03:42 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Made the required rule fail on empty arrays. This makes multiple selects (and probably other elements that returned empty arrays) validate properly. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/rules/required.php Modified: pieforms-php5/trunk/src/pieform/rules/required.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/required.php 2007-12-31 02:03:07 UTC (rev 258) +++ pieforms-php5/trunk/src/pieform/rules/required.php 2007-12-31 02:03:42 UTC (rev 259) @@ -34,7 +34,7 @@ * @return string The error message, if the value is invalid. */ function pieform_rule_required(Pieform $form, $value, $element, $check) {/*{{{*/ - if ($check && $value == '') { + if ($check && ($value == '' || $value == array())) { return $form->i18n('rule', 'required', 'required', $element); } }/*}}}*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 02:03:03
|
Revision: 258 http://pieforms.svn.sourceforge.net/pieforms/?rev=258&view=rev Author: oracleshinoda Date: 2007-12-30 18:03:07 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Added foldmarkers to all files. Updated copyright for all files to 2008 Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/button.php pieforms-php5/trunk/src/pieform/elements/bytes.php pieforms-php5/trunk/src/pieform/elements/calendar.php pieforms-php5/trunk/src/pieform/elements/cancel.php pieforms-php5/trunk/src/pieform/elements/checkbox.php pieforms-php5/trunk/src/pieform/elements/date.php pieforms-php5/trunk/src/pieform/elements/expiry.php pieforms-php5/trunk/src/pieform/elements/file.php pieforms-php5/trunk/src/pieform/elements/hidden.php pieforms-php5/trunk/src/pieform/elements/html.php pieforms-php5/trunk/src/pieform/elements/image.php pieforms-php5/trunk/src/pieform/elements/password.php pieforms-php5/trunk/src/pieform/elements/radio.php pieforms-php5/trunk/src/pieform/elements/select.php pieforms-php5/trunk/src/pieform/elements/submit.php pieforms-php5/trunk/src/pieform/elements/submitcancel.php pieforms-php5/trunk/src/pieform/elements/text.php pieforms-php5/trunk/src/pieform/elements/textarea.php pieforms-php5/trunk/src/pieform/renderers/div.php pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php pieforms-php5/trunk/src/pieform/renderers/oneline.php pieforms-php5/trunk/src/pieform/renderers/table.php pieforms-php5/trunk/src/pieform/rules/before.php pieforms-php5/trunk/src/pieform/rules/email.php pieforms-php5/trunk/src/pieform/rules/integer.php pieforms-php5/trunk/src/pieform/rules/maxlength.php pieforms-php5/trunk/src/pieform/rules/maxvalue.php pieforms-php5/trunk/src/pieform/rules/minlength.php pieforms-php5/trunk/src/pieform/rules/minvalue.php pieforms-php5/trunk/src/pieform/rules/regex.php pieforms-php5/trunk/src/pieform/rules/required.php pieforms-php5/trunk/src/pieform/rules/validateoptions.php Modified: pieforms-php5/trunk/src/pieform/elements/button.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/button.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/button.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -34,13 +34,13 @@ * @return string The HTML for the element * @todo rename to inputbutton */ -function pieform_element_button(Pieform $form, $element) { +function pieform_element_button(Pieform $form, $element) {/*{{{*/ if (!isset($element['value'])) { throw new PieformException('Button elements must have a value'); } return '<input type="button"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($element['value']) . '">'; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/bytes.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/bytes.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/bytes.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @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 + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -32,7 +32,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_bytes(Pieform $form, $element) { +function pieform_element_bytes(Pieform $form, $element) {/*{{{*/ $formname = $form->get_name(); $result = ''; $name = $element['name']; @@ -78,7 +78,7 @@ $uselect .= "</select>\n"; return $numberinput . $uselect; -} +}/*}}}*/ /** * Gets the value of the expiry element and converts it to a time in seconds. @@ -87,7 +87,7 @@ * @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) { +function pieform_element_bytes_get_value(Pieform $form, $element) {/*{{{*/ $name = $element['name']; $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; @@ -103,9 +103,9 @@ return null; } return $number * pieform_element_bytes_in($unit); -} +}/*}}}*/ -function pieform_element_bytes_in($units) { +function pieform_element_bytes_in($units) {/*{{{*/ switch ($units) { case 'megabytes': return 1048576; @@ -117,9 +117,9 @@ return 1; break; }; -} +}/*}}}*/ -function pieform_element_bytes_i18n() { +function pieform_element_bytes_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'bytes' => 'Bytes', @@ -140,13 +140,13 @@ 'invalidvalue' => 'Valeur doit être un nombre', ), ); -} +}/*}}}*/ -function pieform_element_bytes_get_bytes_units() { +function pieform_element_bytes_get_bytes_units() {/*{{{*/ return array('bytes', 'kilobytes', 'megabytes'); -} +}/*}}}*/ -function pieform_element_bytes_get_bytes_from_bytes($bytes) { +function pieform_element_bytes_get_bytes_from_bytes($bytes) {/*{{{*/ if ($bytes == null) { return array('number' => '0', 'units' => 'bytes'); } @@ -158,6 +158,6 @@ } return array('number' => $bytes, 'units' => 'bytes'); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/calendar.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/calendar.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/calendar.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -34,7 +34,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_calendar(Pieform $form, $element) { +function pieform_element_calendar(Pieform $form, $element) {/*{{{*/ $id = $form->get_name() . '_' . $element['name']; $value = $form->get_value($element); if ($value) { @@ -66,7 +66,7 @@ $result .= '<script type="text/javascript">Calendar.setup(' . $encodedoptions . ');</script>'; return $result; -} +}/*}}}*/ /** * Sets default attributes of the calendar element. @@ -74,14 +74,14 @@ * @param array $element The element to configure * @return array The configured element */ -function pieform_element_calendar_set_attributes($element) { +function pieform_element_calendar_set_attributes($element) {/*{{{*/ $element['jsroot'] = isset($element['jsroot']) ? $element['jsroot'] : ''; $element['language'] = isset($element['language']) ? $element['language'] : 'en'; $element['theme'] = isset($element['theme']) ? $element['theme'] : 'calendar-win2k-2'; $element['caloptions']['ifFormat'] = isset($element['caloptions']['ifFormat']) ? $element['caloptions']['ifFormat'] : '%Y/%m/%d'; $element['caloptions']['daFormat'] = isset($element['caloptions']['daFormat']) ? $element['caloptions']['daFormat'] : '%Y/%m/%d'; return $element; -} +}/*}}}*/ /** * Returns code to go in <head> for the given calendar instance @@ -89,7 +89,7 @@ * @param array $element The element to get <head> code for * @return array An array of HTML elements to go in the <head> */ -function pieform_element_calendar_get_headdata($element) { +function pieform_element_calendar_get_headdata($element) {/*{{{*/ if (isset($element['themefile'])) { $themefile = $element['themefile']; } @@ -109,7 +109,7 @@ '<script type="text/javascript" src="' . $setupfile . '"></script>' ); return $result; -} +}/*}}}*/ /** * Retrieves the value of the calendar as a unix timestamp @@ -118,7 +118,7 @@ * @param array $element The element to get the value for * @return int The unix timestamp represented by the calendar */ -function pieform_element_calendar_get_value(Pieform $form, $element) { +function pieform_element_calendar_get_value(Pieform $form, $element) {/*{{{*/ $name = $element['name']; $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; @@ -145,12 +145,12 @@ } return null; -} +}/*}}}*/ /** * i18n for calendar */ -function pieform_element_calendar_i18n() { +function pieform_element_calendar_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'invalidvalue' => 'Invalid date/time specified' @@ -162,6 +162,6 @@ 'invalidvalue' => 'Date/Heure indiquée invalide' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/cancel.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/cancel.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/cancel.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -33,7 +33,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_cancel(Pieform $form, $element) { +function pieform_element_cancel(Pieform $form, $element) {/*{{{*/ if (!isset($element['value'])) { throw new PieformException('Cancel elements must have a value'); } @@ -44,11 +44,11 @@ return '<input type="submit"' . $attributes . ' value="' . Pieform::hsc($element['value']) . '">'; -} +}/*}}}*/ -function pieform_element_cancel_set_attributes($element) { +function pieform_element_cancel_set_attributes($element) {/*{{{*/ $element['cancelelement'] = true; return $element; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/checkbox.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/checkbox.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/checkbox.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_checkbox(Pieform $form, $element) { +function pieform_element_checkbox(Pieform $form, $element) {/*{{{*/ $checked = false; if (!empty($element['value'])) { $checked = true; @@ -48,9 +48,9 @@ . $form->element_attributes($element) . ($checked ? ' checked="checked"' : '') . '>'; -} +}/*}}}*/ -function pieform_element_checkbox_get_value(Pieform $form, $element) { +function pieform_element_checkbox_get_value(Pieform $form, $element) {/*{{{*/ $name = $element['name']; $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; @@ -70,6 +70,6 @@ } return false; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/date.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/date.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/date.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_date(Pieform $form, $element) { +function pieform_element_date(Pieform $form, $element) {/*{{{*/ $result = ''; $name = $element['name']; $element['minyear'] = (isset($element['minyear'])) ? intval($element['minyear']) : 1950; @@ -104,7 +104,7 @@ } return $result; -} +}/*}}}*/ /** * Gets the value of the date element from the request and converts it into a @@ -113,7 +113,7 @@ * @param Pieform $form The form the element is attached to * @param array $element The element to get the value for */ -function pieform_element_date_get_value(Pieform $form, $element) { +function pieform_element_date_get_value(Pieform $form, $element) {/*{{{*/ $name = $element['name']; $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; if ( isset($global[$name . '_day']) && isset($global[$name . '_month']) && isset($global[$name . '_year']) ) { @@ -125,9 +125,9 @@ } return null; -} +}/*}}}*/ -function pieform_element_date_i18n() { +function pieform_element_date_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'or' => 'or', @@ -142,10 +142,10 @@ 'notspecified' => 'Non indiqué' ), ); -} +}/*}}}*/ /** helper: used when rendering the element, to get the value for it */ -function pieform_element_date_get_timeperiod_value($timeperiod, $min, $max, $element, Pieform $form) { +function pieform_element_date_get_timeperiod_value($timeperiod, $min, $max, $element, Pieform $form) {/*{{{*/ static $lookup = array( 'year' => 0, 'month' => 1, @@ -189,6 +189,6 @@ } return $value; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/expiry.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/expiry.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/expiry.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Richard Mansfield <ric...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -32,7 +32,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_expiry(Pieform $form, $element) { +function pieform_element_expiry(Pieform $form, $element) {/*{{{*/ $formname = $form->get_name(); $result = ''; $name = $element['name']; @@ -98,7 +98,7 @@ EOJS; return $numberinput . $uselect . $script; -} +}/*}}}*/ /** * Gets the value of the expiry element and converts it to a time in seconds. @@ -107,7 +107,7 @@ * @param array $element The element to get the value for * @return int The number of seconds until expiry */ -function pieform_element_expiry_get_value(Pieform $form, $element) { +function pieform_element_expiry_get_value(Pieform $form, $element) {/*{{{*/ $name = $element['name']; $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; $unit = $global[$name . '_units']; @@ -120,9 +120,9 @@ return null; } return $number * pieform_element_expiry_seconds_in($unit); -} +}/*}}}*/ -function pieform_element_expiry_i18n() { +function pieform_element_expiry_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'days' => 'Days', @@ -146,13 +146,13 @@ 'noenddate' => 'Pas de date de fin' ), ); -} +}/*}}}*/ -function pieform_element_expire_get_expiry_units() { +function pieform_element_expire_get_expiry_units() {/*{{{*/ return array('days', 'weeks', 'months', 'years', 'noenddate'); -} +}/*}}}*/ -function pieform_element_expiry_seconds_in($unit) { +function pieform_element_expiry_seconds_in($unit) {/*{{{*/ $dayseconds = 60 * 60 * 24; switch ($unit) { case 'days' : return $dayseconds; @@ -161,9 +161,9 @@ case 'years' : return $dayseconds * 365; default : return null; } -} +}/*}}}*/ -function pieform_element_expiry_get_expiry_from_seconds($seconds) { +function pieform_element_expiry_get_expiry_from_seconds($seconds) {/*{{{*/ if ($seconds == null) { return array('number' => '', 'units' => 'noenddate'); } @@ -186,6 +186,6 @@ return array('number' => (int) ($seconds / $dayseconds), 'units' => 'days'); } return null; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/file.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/file.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/file.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,18 +31,18 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_file(Pieform $form, $element) { +function pieform_element_file(Pieform $form, $element) {/*{{{*/ return '<input type="file"' . $form->element_attributes($element) . '>'; -} +}/*}}}*/ -function pieform_element_file_get_value(Pieform $form, $element) { +function pieform_element_file_get_value(Pieform $form, $element) {/*{{{*/ if (isset($_FILES[$element['name']])) { if (!$_FILES[$element['name']]['error']) { return $_FILES[$element['name']]; } return null; } -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/hidden.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/hidden.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/hidden.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_hidden(Pieform $form, $element) { +function pieform_element_hidden(Pieform $form, $element) {/*{{{*/ if (!isset($element['value'])) { throw new PieformException('The hidden element "' . $element['name'] . '" must have a value set'); } @@ -47,14 +47,14 @@ return '<input type="hidden"' . $form->element_attributes($element, array('accesskey', 'onclick', 'size', 'style', 'tabindex')) . ' value="' . Pieform::hsc($form->get_value($element)) . "\">\n"; -} +}/*}}}*/ /** * Returns the value for a hidden element. Hidden elements only listen to the * 'value' index, and not to GET/POST */ -function pieform_element_hidden_get_value(Pieform $form, $element) { +function pieform_element_hidden_get_value(Pieform $form, $element) {/*{{{*/ return $element['value']; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/html.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/html.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/html.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Penny Leach <pe...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -32,14 +32,14 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_element_html(Pieform $form, $element) { +function pieform_element_html(Pieform $form, $element) {/*{{{*/ return $element['value']; -} +}/*}}}*/ -function pieform_element_html_set_attributes($element) { +function pieform_element_html_set_attributes($element) {/*{{{*/ $element['nolabel'] = true; $element['nofocus'] = true; return $element; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/image.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/image.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/image.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_image(Pieform $form, $element) { +function pieform_element_image(Pieform $form, $element) {/*{{{*/ if (!isset($element['src'])) { throw new PieformException('"image" elements must have a "src" for the image'); } @@ -41,14 +41,14 @@ return '<input type="image" src="' . Pieform::hsc($element['src']) . '"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; -} +}/*}}}*/ -function pieform_element_image_set_attributes($element) { +function pieform_element_image_set_attributes($element) {/*{{{*/ $element['submitelement'] = true; return $element; -} +}/*}}}*/ -function pieform_element_image_get_value(Pieform $form, $element) { +function pieform_element_image_get_value(Pieform $form, $element) {/*{{{*/ if (isset($element['value'])) { return $element['value']; } @@ -59,6 +59,6 @@ } return null; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/password.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/password.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/password.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,13 +31,13 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_element_password(Pieform $form, $element) { +function pieform_element_password(Pieform $form, $element) {/*{{{*/ return '<input type="password"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; -} +}/*}}}*/ -function pieform_element_password_get_value(Pieform $form, $element) { +function pieform_element_password_get_value(Pieform $form, $element) {/*{{{*/ $global = ($form->get_property('method') == 'get') ? $_GET : $_POST; if (isset($global[$element['name']])) { return $global[$element['name']]; @@ -46,6 +46,6 @@ return $element['value']; } return null; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/radio.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/radio.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/radio.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_element_radio(Pieform $form, $element) { +function pieform_element_radio(Pieform $form, $element) {/*{{{*/ if (!isset($element['options']) || !is_array($element['options']) || count($element['options']) < 1) { throw new PieformException('Radio elements should have at least one option'); } @@ -57,12 +57,12 @@ $result = substr($result, 0, -strlen($separator)); return $result; -} +}/*}}}*/ -function pieform_element_radio_set_attributes($element) { +function pieform_element_radio_set_attributes($element) {/*{{{*/ $element['nolabel'] = true; $element['rules']['validateoptions'] = true; return $element; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/select.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/select.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/select.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -35,7 +35,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_select(Pieform $form, $element) { +function pieform_element_select(Pieform $form, $element) {/*{{{*/ if (!empty($element['multiple'])) { $element['name'] .= '[]'; } @@ -120,17 +120,17 @@ $result .= '</select>'; return $result; -} +}/*}}}*/ -function pieform_element_select_set_attributes($element) { +function pieform_element_select_set_attributes($element) {/*{{{*/ if (!isset($element['collapseifoneoption'])) { $element['collapseifoneoption'] = true; } $element['rules']['validateoptions'] = true; return $element; -} +}/*}}}*/ -function pieform_element_select_get_value(Pieform $form, $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'])) { @@ -169,6 +169,6 @@ } return $values; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/submit.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/submit.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/submit.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_submit(Pieform $form, $element) { +function pieform_element_submit(Pieform $form, $element) {/*{{{*/ if (isset($element['confirm'])) { $element['onclick'] = 'return confirm(' . json_encode($element['confirm']) . ');'; } @@ -39,11 +39,11 @@ return '<input type="submit"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; -} +}/*}}}*/ -function pieform_element_submit_set_attributes($element) { +function pieform_element_submit_set_attributes($element) {/*{{{*/ $element['submitelement'] = true; return $element; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/submitcancel.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/submitcancel.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/submitcancel.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_submitcancel(Pieform $form, $element) { +function pieform_element_submitcancel(Pieform $form, $element) {/*{{{*/ if (!isset($element['value']) || !is_array($element['value']) || count($element['value']) != 2) { throw new PieformException('The submitcancel element "' . $element['name'] . '" must have a two element array for its value'); @@ -43,20 +43,20 @@ $cancelelement = $element; $cancelelement['value'] = $element['value'][1]; return pieform_element_submit($form, $submitelement) . ' ' . pieform_element_cancel($form, $cancelelement); -} +}/*}}}*/ -function pieform_element_submitcancel_set_attributes($element) { +function pieform_element_submitcancel_set_attributes($element) {/*{{{*/ $element['submitelement'] = true; return $element; -} +}/*}}}*/ -function pieform_element_submitcancel_get_value(Pieform $form, $element) { +function pieform_element_submitcancel_get_value(Pieform $form, $element) {/*{{{*/ if (is_array($element['value'])) { return $element['value'][0]; } else { return $element['value']; } -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/text.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/text.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/text.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,10 +31,10 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_text(Pieform $form, $element) { +function pieform_element_text(Pieform $form, $element) {/*{{{*/ return '<input type="text"' . $form->element_attributes($element) . ' value="' . Pieform::hsc($form->get_value($element)) . '">'; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/elements/textarea.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/textarea.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/elements/textarea.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param Pieform $form The form to render the element for * @return string The HTML for the element */ -function pieform_element_textarea(Pieform $form, $element) { +function pieform_element_textarea(Pieform $form, $element) {/*{{{*/ $rows = $cols = $style = ''; if (isset($element['height'])) { $style .= 'height:' . $element['height'] . ';'; @@ -64,9 +64,9 @@ . (($cols) ? ' cols="' . $cols . '"' : '') . $form->element_attributes($element, array('maxlength', 'size')) . '>' . Pieform::hsc($form->get_value($element)) . '</textarea>'; -} +}/*}}}*/ -function pieform_element_textarea_get_value(Pieform $form, $element) { +function pieform_element_textarea_get_value(Pieform $form, $element) {/*{{{*/ if (isset($element['value'])) { return $element['value']; } @@ -81,6 +81,6 @@ } return ''; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/renderers/div.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/div.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/renderers/div.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage renderer * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to be rendered * @return string The element rendered inside an appropriate container */ -function pieform_renderer_div(Pieform $form, $element) { +function pieform_renderer_div(Pieform $form, $element) {/*{{{*/ $formname = $form->get_name(); // Set the class of the enclosing <div> to match that of the element $result = '<div'; @@ -66,10 +66,10 @@ $result .= "</div>\n"; return $result; -} +}/*}}}*/ -function pieform_renderer_div_get_js($id) { +function pieform_renderer_div_get_js($id) {/*{{{*/ $result = <<<EOF // Given a message and form element name, should set an error on the element function {$id}_set_error(message, element) { @@ -88,6 +88,6 @@ } EOF; return $result; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/renderers/multicolumntable.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage renderer * @author Penny Leach <pe...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -37,13 +37,13 @@ * @param array $element The element to be rendered * @return string The element rendered inside an appropriate container */ -function pieform_renderer_multicolumntable(Pieform $form, $element) { +function pieform_renderer_multicolumntable(Pieform $form, $element) {/*{{{*/ global $formrenderermct; $formrenderermct->add_element($element['html'], $element); $formrenderermct->set_form($form); -} +}/*}}}*/ -function pieform_renderer_multicolumntable_get_js($id) { +function pieform_renderer_multicolumntable_get_js($id) {/*{{{*/ return <<<EOF function {$id}_set_error (message, element) { element = '{$id}_' + element; @@ -78,19 +78,19 @@ }); } EOF; -} +}/*}}}*/ -function pieform_renderer_multicolumntable_header() { +function pieform_renderer_multicolumntable_header() {/*{{{*/ global $formrenderermct; $formrenderermct = new FormRendererMultiColumnTable(); -} +}/*}}}*/ -function pieform_renderer_multicolumntable_footer() { +function pieform_renderer_multicolumntable_footer() {/*{{{*/ global $formrenderermct; return $formrenderermct->build(); -} +}/*}}}*/ -class FormRendererMultiColumnTable { +class FormRendererMultiColumnTable {/*{{{*/ private $elements = array(); private $form; @@ -172,6 +172,6 @@ return $result; } -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/renderers/oneline.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/oneline.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/renderers/oneline.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,17 +20,17 @@ * @subpackage renderer * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ -function pieform_renderer_oneline_header() { +function pieform_renderer_oneline_header() {/*{{{*/ return '<div>'; -} +}/*}}}*/ -function pieform_renderer_oneline_footer() { +function pieform_renderer_oneline_footer() {/*{{{*/ return '</div>'; -} +}/*}}}*/ /** * Renders form elements all on one line. @@ -39,7 +39,7 @@ * @param array $element The element that is being rendered * @return string The element rendered inside an appropriate container */ -function pieform_renderer_oneline(Pieform $form, $element) { +function pieform_renderer_oneline(Pieform $form, $element) {/*{{{*/ $formname = $form->get_name(); // Set the class of the enclosing <div> to match that of the element $result = '<span'; @@ -68,13 +68,13 @@ $result .= "</span>"; return $result; -} +}/*}}}*/ -function pieform_renderer_oneline_get_js($id) { +function pieform_renderer_oneline_get_js($id) {/*{{{*/ return <<<EOF function {$id}_remove_all_errors () {} function {$id}_set_error () {} EOF; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/renderers/table.php =================================================================== --- pieforms-php5/trunk/src/pieform/renderers/table.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/renderers/table.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage renderer * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -31,7 +31,7 @@ * @param array $element The element to be rendered * @return string The element rendered inside an appropriate container */ -function pieform_renderer_table(Pieform $form, $element) { +function pieform_renderer_table(Pieform $form, $element) {/*{{{*/ $formname = $form->get_name(); if ($element['type'] == 'fieldset') { // Add table tags to the build element, to preserve HTML compliance @@ -92,17 +92,17 @@ } return $result; -} +}/*}}}*/ -function pieform_renderer_table_header() { +function pieform_renderer_table_header() {/*{{{*/ return "<table cellspacing=\"0\"><tbody>\n"; -} +}/*}}}*/ -function pieform_renderer_table_footer() { +function pieform_renderer_table_footer() {/*{{{*/ return "</tbody></table>\n"; -} +}/*}}}*/ -function pieform_renderer_table_get_js($id) { +function pieform_renderer_table_get_js($id) {/*{{{*/ $result = <<<EOF function {$id}_set_error(message, element) { element = $('{$id}_' + element + '_container'); @@ -122,6 +122,6 @@ } EOF; return $result; -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/before.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/before.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/before.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -35,15 +35,15 @@ * @param string $otherelement The other element to check for * @return string The error message, if the value is invalid. */ -function pieform_rule_before(Pieform $form, $value, $element, $otherelement) { +function pieform_rule_before(Pieform $form, $value, $element, $otherelement) {/*{{{*/ $otherelement = $form->get_element($otherelement); $othervalue = $form->get_value($otherelement); if ($value != '' && $othervalue != '' && intval($value) > intval($othervalue)) { return sprintf($form->i18n('rule', 'before', 'before', $element), $otherelement['title']); } -} +}/*}}}*/ -function pieform_rule_before_i18n() { +function pieform_rule_before_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'before' => 'This can not be after the field "%s"' @@ -55,6 +55,6 @@ 'before' => 'Ceci ne peut pas être placé après le champ "%s"' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/email.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/email.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/email.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -36,13 +36,13 @@ * @return string The error message, if there is something wrong with * the address. */ -function pieform_rule_email(Pieform $form, $value, $element) { +function pieform_rule_email(Pieform $form, $value, $element) {/*{{{*/ if (!preg_match('/^[a-z0-9\._%-]+@(?:[a-z0-9-]+\.)+[a-z]{2,4}$/', $value)) { return $form->i18n('rule', 'email', 'email', $element); } -} +}/*}}}*/ -function pieform_rule_email_i18n() { +function pieform_rule_email_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'email' => 'E-mail address is invalid' @@ -54,6 +54,6 @@ 'email' => 'Cette adresse de courriel n\'est pas valide' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/integer.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/integer.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/integer.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Penny Leach <pe...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -33,13 +33,13 @@ * @return string The error message, if there is something wrong with * the address. */ -function pieform_rule_integer(Pieform $form, $value, $element) { +function pieform_rule_integer(Pieform $form, $value, $element) {/*{{{*/ if (!is_numeric($value) || $value != (int)$value) { return $form->i18n('rule', 'integer', 'integer', $element); } -} +}/*}}}*/ -function pieform_rule_integer_i18n() { +function pieform_rule_integer_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'integer' => 'The field must be an integer' @@ -51,6 +51,6 @@ 'integer' => 'Ce champ doit être un nombre entier' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/maxlength.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/maxlength.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/maxlength.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -33,13 +33,13 @@ * @param int $maxlength The length to check for * @return string The error message, if the value is invalid. */ -function pieform_rule_maxlength(Pieform $form, $value, $element, $maxlength) { +function pieform_rule_maxlength(Pieform $form, $value, $element, $maxlength) {/*{{{*/ if (strlen($value) > $maxlength) { return sprintf($form->i18n('rule', 'maxlength', 'maxlength', $element), $maxlength); } -} +}/*}}}*/ -function pieform_rule_maxlength_i18n() { +function pieform_rule_maxlength_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'maxlength' => 'This field must be at most %d characters long' @@ -51,6 +51,6 @@ 'maxlength' => 'Ce champ ne peut pas contenir plus de %d signes' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/maxvalue.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/maxvalue.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/maxvalue.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -33,13 +33,13 @@ * @param int $maxvalue The value to check for * @return string The error message, if the value is invalid. */ -function pieform_rule_maxvalue(Pieform $form, $value, $element, $maxvalue) { +function pieform_rule_maxvalue(Pieform $form, $value, $element, $maxvalue) {/*{{{*/ if ($value != '' && intval($value) > $maxvalue) { return sprintf($form->i18n('rule', 'maxvalue', 'maxvalue', $element), $maxvalue); } -} +}/*}}}*/ -function pieform_rule_maxvalue_i18n() { +function pieform_rule_maxvalue_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'maxvalue' => 'This value can not be larger than %d' @@ -51,6 +51,6 @@ 'maxvalue' => 'Cette valeur ne peut pas supérieure à %d' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/minlength.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/minlength.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/minlength.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -33,13 +33,13 @@ * @param int $minlength The length to check for * @return string The error message, if the value is invalid. */ -function pieform_rule_minlength(Pieform $form, $value, $element, $minlength) { +function pieform_rule_minlength(Pieform $form, $value, $element, $minlength) {/*{{{*/ if (strlen($value) < $minlength) { return sprintf($form->i18n('rule', 'minlength', 'minlength', $element), $minlength); } -} +}/*}}}*/ -function pieform_rule_minlength_i18n() { +function pieform_rule_minlength_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'minlength' => 'This field must be at least %d characters long', @@ -51,6 +51,6 @@ 'minlength' => 'Ce champ doit contenir au moins %d caractères', ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/minvalue.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/minvalue.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/minvalue.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -33,13 +33,13 @@ * @param int $maxlength The value to check for * @return string The error message, if the value is invalid. */ -function pieform_rule_minvalue(Pieform $form, $value, $element, $minvalue) { +function pieform_rule_minvalue(Pieform $form, $value, $element, $minvalue) {/*{{{*/ if ($value != '' && intval($value) < $minvalue) { return sprintf($form->i18n('rule', 'minvalue', 'minvalue', $element), $minvalue); } -} +}/*}}}*/ -function pieform_rule_minvalue_i18n() { +function pieform_rule_minvalue_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'minvalue' => 'This value can not be smaller than %d' @@ -51,6 +51,6 @@ 'minvalue' => 'Cette valeur ne peut pas être inférieure à %d' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/regex.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/regex.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/regex.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -34,13 +34,13 @@ * @return string The error message, if there is something wrong with * the value. */ -function pieform_rule_regex(Pieform $form, $value, $element, $regex) { +function pieform_rule_regex(Pieform $form, $value, $element, $regex) {/*{{{*/ if (!preg_match($regex, $value)) { return $form->i18n('rule', 'regex', 'regex', $element); } -} +}/*}}}*/ -function pieform_rule_regex_i18n() { +function pieform_rule_regex_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'regex' => 'This field is not in valid form' @@ -52,6 +52,6 @@ 'regex' => 'Ce champ n\'a pas une forme correcte' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/required.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/required.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/required.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -33,13 +33,13 @@ * @param string $check Whether to check the element * @return string The error message, if the value is invalid. */ -function pieform_rule_required(Pieform $form, $value, $element, $check) { +function pieform_rule_required(Pieform $form, $value, $element, $check) {/*{{{*/ if ($check && $value == '') { return $form->i18n('rule', 'required', 'required', $element); } -} +}/*}}}*/ -function pieform_rule_required_i18n() { +function pieform_rule_required_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'required' => 'This field is required' @@ -51,6 +51,6 @@ 'required' => 'Ce champ est obligatoire' ), ); -} +}/*}}}*/ ?> Modified: pieforms-php5/trunk/src/pieform/rules/validateoptions.php =================================================================== --- pieforms-php5/trunk/src/pieform/rules/validateoptions.php 2007-12-31 02:01:32 UTC (rev 257) +++ pieforms-php5/trunk/src/pieform/rules/validateoptions.php 2007-12-31 02:03:07 UTC (rev 258) @@ -20,7 +20,7 @@ * @subpackage rule * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -34,7 +34,7 @@ * @param string $element The element being checked * @return string The error message, if the value is invalid. */ -function pieform_rule_validateoptions(Pieform $form, $field, $element) { +function pieform_rule_validateoptions(Pieform $form, $field, $element) {/*{{{*/ // Get the value into an array as a key if it's a scalar, since // the actual check involves array keys $field = (array) $field; @@ -45,9 +45,9 @@ return sprintf($form->i18n('rule', 'validateoptions', 'validateoptions', $element), $key); } } -} +}/*}}}*/ -function pieform_rule_validateoptions_i18n() { +function pieform_rule_validateoptions_i18n() {/*{{{*/ return array( 'en.utf8' => array( 'validateoptions' => 'The option "%s" is invalid' @@ -59,6 +59,6 @@ 'validateoptions' => 'Cette option "%s" n\'est pas valide' ), ); -} +}/*}}}*/ ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 02:01:28
|
Revision: 257 http://pieforms.svn.sourceforge.net/pieforms/?rev=257&view=rev Author: oracleshinoda Date: 2007-12-30 18:01:32 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Removed a done TODO Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 02:01:02 UTC (rev 256) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 02:01:32 UTC (rev 257) @@ -276,7 +276,6 @@ // Set some attributes for all elements $autofocusadded = false; foreach ($this->elementrefs as $name => &$element) { - // @todo re-check ordering of this section if (count($element) == 0) { throw new PieformException('An element in form "' . $this->name . '" has no data (' . $name . ')'); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 02:01:00
|
Revision: 256 http://pieforms.svn.sourceforge.net/pieforms/?rev=256&view=rev Author: oracleshinoda Date: 2007-12-30 18:01:02 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Moved the default values for the pieform data into its own method. This should help readability of the constructor. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 02:00:39 UTC (rev 255) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 02:01:02 UTC (rev 256) @@ -193,118 +193,8 @@ } // Assign defaults for the form - $formdefaults = array( - // The method used to submit the form, should always be 'get' or 'post' - 'method' => 'get', + $this->data = array_merge(self::get_pieform_defaults(), $formconfig, $data); - // The form target. The vast majority of the time this should be blank, - // as the functions that handle the submit should be in the same script - // as the form definition - 'action' => '', - - // The form elements - 'elements' => array(), - - // The form renderer (see the pieform/renderers directory) - 'renderer' => 'table', - - // The directory (relative to the include path) to search for templates - 'templatedir' => '', - - // Whether to ignore E_NOTICE messages in templates - 'ignoretemplatenotices' => true, - - // Whether to validate the form. Non validated forms have none of the - // validate, success or error callbacks called on them - 'validate' => true, - - // Whether to process the submission of this form. The form will still - // be validated. Handy if the code handling the submission is elsewhere - 'submit' => true, - - // The PHP callback called to validate the form. Optional - 'validatecallback' => '', - - // The PHP callback called to process the submission of the form. - // Required, unless a success function is provided for each submit - // button in the form - 'successcallback' => '', - - // The PHP callback called if there is any validation error. Optional - 'errorcallback' => '', - - // Whether this form should submit to a hidden iframe and use DOM - // manipulation to insert error messages (faster than a normal submit, - // supported in less browsers. Most modern browsers should be fine) - 'jsform' => false, - - // The javascript function called before submission of a form - // (regardless of whether the form is a jsform) - 'presubmitcallback' => '', - - // The javascript function called after submission of a form. As non-js - // forms will trigger a page load on submit, this has no effect for them. - 'postsubmitcallback' => '', - - // The javascript function called if the form submission was successful - 'jssuccesscallback' => '', - - // The javascript function called if the form submission was unsuccessful - 'jserrorcallback' => '', - - // The javascript function called if the form submission returned an - // unknown error code - 'globaljserrorcallback' => '', - - // The message to pass back as a reason for the form submission failing - // if the form is a jsform. This can be used by your application however - // you choose. - 'jserrormessage' => '', - - // Whether this form can be cancelled, regardless of the presence of - // 'cancel' buttons or form inputs mischeviously named as to behave - // like cancel buttons - 'iscancellable' => true, - - // Whether Pieforms should die after calling a submit function. Generally - // this is a good idea, as it forces the user to reply to the form - // submission. However, there are occasions where you might want to let - // it continue, so this behaviour can be turned off - 'dieaftersubmit' => true, - - // Whether to auto-focus either the first field (if the value is true, - // or the named field (if the value is a string) when the form is - // displayed. If this has any value other than false and the form has - // been submitted with an error, the first field with an error will - // be focussed. - 'autofocus' => false, - - // The directories to search for additional elements, renderers and - // rules - 'configdirs' => array(), - - // The language to use for any form strings, such as those found in - // rules. - 'language' => 'en.utf8', - - // Any overriding language strings for rules - 'rulei18n' => array(), - - // The tabindex for the form (managed automatically by Pieforms) - 'tabindex' => false, - - // Whether to add a class of the type of the element to each element - 'elementclasses' => false, - - // Whether to add * markers after each required field - 'requiredmarker' => false, - - // Whether to show the description as well as the error message - // when displaying errors - 'showdescriptiononerror' => true, - ); - $this->data = array_merge($formdefaults, $formconfig, $data); - // Set the method - only get/post allowed $this->data['method'] = strtolower($this->data['method']); if ($this->data['method'] != 'post') { @@ -1419,6 +1309,127 @@ } }/*}}}*/ + /** + * Returns the default values for pieform data. + * + * Used in the constructor when setting up the pieform. + * + * @return array + * {@internal {PHP5 doesn't support private static const arrays, so this is a method}} + */ + private static function get_pieform_defaults() {/*{{{*/ + return array( + // The method used to submit the form, should always be 'get' or 'post' + 'method' => 'get', + + // The form target. The vast majority of the time this should be blank, + // as the functions that handle the submit should be in the same script + // as the form definition + 'action' => '', + + // The form elements + 'elements' => array(), + + // The form renderer (see the pieform/renderers directory) + 'renderer' => 'table', + + // The directory (relative to the include path) to search for templates + 'templatedir' => '', + + // Whether to ignore E_NOTICE messages in templates + 'ignoretemplatenotices' => true, + + // Whether to validate the form. Non validated forms have none of the + // validate, success or error callbacks called on them + 'validate' => true, + + // Whether to process the submission of this form. The form will still + // be validated. Handy if the code handling the submission is elsewhere + 'submit' => true, + + // The PHP callback called to validate the form. Optional + 'validatecallback' => '', + + // The PHP callback called to process the submission of the form. + // Required, unless a success function is provided for each submit + // button in the form + 'successcallback' => '', + + // The PHP callback called if there is any validation error. Optional + 'errorcallback' => '', + + // Whether this form should submit to a hidden iframe and use DOM + // manipulation to insert error messages (faster than a normal submit, + // supported in less browsers. Most modern browsers should be fine) + 'jsform' => false, + + // The javascript function called before submission of a form + // (regardless of whether the form is a jsform) + 'presubmitcallback' => '', + + // The javascript function called after submission of a form. As non-js + // forms will trigger a page load on submit, this has no effect for them. + 'postsubmitcallback' => '', + + // The javascript function called if the form submission was successful + 'jssuccesscallback' => '', + + // The javascript function called if the form submission was unsuccessful + 'jserrorcallback' => '', + + // The javascript function called if the form submission returned an + // unknown error code + 'globaljserrorcallback' => '', + + // The message to pass back as a reason for the form submission failing + // if the form is a jsform. This can be used by your application however + // you choose. + 'jserrormessage' => '', + + // Whether this form can be cancelled, regardless of the presence of + // 'cancel' buttons or form inputs mischeviously named as to behave + // like cancel buttons + 'iscancellable' => true, + + // Whether Pieforms should die after calling a submit function. Generally + // this is a good idea, as it forces the user to reply to the form + // submission. However, there are occasions where you might want to let + // it continue, so this behaviour can be turned off + 'dieaftersubmit' => true, + + // Whether to auto-focus either the first field (if the value is true, + // or the named field (if the value is a string) when the form is + // displayed. If this has any value other than false and the form has + // been submitted with an error, the first field with an error will + // be focussed. + 'autofocus' => false, + + // The directories to search for additional elements, renderers and + // rules + 'configdirs' => array(), + + // The language to use for any form strings, such as those found in + // rules. + 'language' => 'en.utf8', + + // Any overriding language strings for rules + 'rulei18n' => array(), + + // The tabindex for the form (managed automatically by Pieforms) + 'tabindex' => false, + + // Whether to add a class of the type of the element to each element + 'elementclasses' => false, + + // Whether to add * markers after each required field + 'requiredmarker' => false, + + // Whether to show the description as well as the error message + // when displaying errors + 'showdescriptiononerror' => true, + ); + }/*}}}*/ + }/*}}}*/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 02:00:39
|
Revision: 255 http://pieforms.svn.sourceforge.net/pieforms/?rev=255&view=rev Author: oracleshinoda Date: 2007-12-30 18:00:39 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Linewrapped a comment properly. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 02:00:15 UTC (rev 254) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 02:00:39 UTC (rev 255) @@ -124,8 +124,8 @@ /** * A hash of references to the elements of the form, not including - * fieldsets (although including all elements inside any fieldsets. Used internally - * for simplifying looping over elements + * fieldsets (although including all elements inside any fieldsets. Used + * internally for simplifying looping over elements * * @var array */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 02:00:10
|
Revision: 254 http://pieforms.svn.sourceforge.net/pieforms/?rev=254&view=rev Author: oracleshinoda Date: 2007-12-30 18:00:15 -0800 (Sun, 30 Dec 2007) Log Message: ----------- A new datastructure to speed up and simplify looping through elements. Added 'elementrefs' structure, containing references to all elements in the form, minus fieldsets. Changed calls to get_elements to use elementrefs. Simplified a bunch of code using this. For example, a whole bunch of duplicated checking in the constructor has been consolidated now that it's easier to loop through all elements without having to take fieldsets into account. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 01:59:52 UTC (rev 253) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 02:00:15 UTC (rev 254) @@ -123,6 +123,15 @@ private $data = array(); /** + * A hash of references to the elements of the form, not including + * fieldsets (although including all elements inside any fieldsets. Used internally + * for simplifying looping over elements + * + * @var array + */ + private $elementrefs = array(); + + /** * Whether this form includes a file element. If so, the enctype attribute * for the form will be specified as "multipart/mixed" as required. This * is auto-detected by the Pieform class. @@ -328,165 +337,123 @@ 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'); + // Get references to all the elements in the form, excluding fieldsets + foreach ($this->data['elements'] as $name => &$_element) { + if (isset($_element['type']) && $_element['type'] == 'fieldset') { + // Load the fieldset plugin as we know this form has one now + $this->include_plugin('element', 'fieldset'); + if ($this->get_property('template')) { + self::info("Your form '$this->name' has a fieldset, but is using a template. Fieldsets make no sense when using templates"); + } + + foreach ($_element['elements'] as $subname => &$_subelement) { + $this->elementrefs[$subname] = &$_subelement; + } } - $elements[$newname] = $element; + else { + $this->elementrefs[$name] = &$_element; + } } - $this->data['elements'] = $elements; + // Check that all elements have names compliant to PHP's variable naming policy + // (otherwise things get messy later) + foreach (array_keys($this->elementrefs) as $name) { + if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $name)) { + throw new PieformException('Element "' . $name . '" is badly named (validity test: could you give a PHP variable the name?)'); + } + } + // Remove elements to ignore + // This can't be done using $this->elementrefs, because you can't unset + // an entry in there and have it unset the entry in $this->data['elements'] foreach ($this->data['elements'] as $name => $element) { if (isset($element['type']) && $element['type'] == 'fieldset') { foreach ($element['elements'] as $subname => $subelement) { if (!empty($subelement['ignore'])) { unset ($this->data['elements'][$name]['elements'][$subname]); + unset($this->elementrefs[$subname]); } } } else { if (!empty($element['ignore'])) { unset($this->data['elements'][$name]); + unset($this->elementrefs[$name]); } } } // Set some attributes for all elements $autofocusadded = false; - foreach ($this->data['elements'] as $name => &$element) { + foreach ($this->elementrefs as $name => &$element) { // @todo re-check ordering of this section - // The name can be in the element itself. This is compatibility for the perl version - if (isset($element['name'])) { - $name = $element['name']; - } if (count($element) == 0) { throw new PieformException('An element in form "' . $this->name . '" has no data (' . $name . ')'); } - if (!isset($element['type'])) { + + if (!isset($element['type']) || $element['type'] == 'markup') { $element['type'] = 'markup'; if (!isset($element['value'])) { throw new PieformException('The markup element "' . $name . '" has no value'); } } - if (!isset($element['title'])) { - $element['title'] = ''; - } - if ($element['type'] == 'file') { - $this->fileupload = true; - if ($this->data['method'] == 'get') { - $this->data['method'] = 'post'; - self::info("Your form '$this->name' had the method 'get' and also a file element - it has been converted to 'post'"); + else { + // Now we know what type the element is, we can load the plugin for it + $this->include_plugin('element', $element['type']); + + // The name can be in the element itself. This is compatibility for the perl version + if (isset($element['name'])) { + $name = $element['name']; } - } - if ($element['type'] == 'fieldset') { - if ($this->get_property('template')) { - self::info("Your form '$this->name' has a fieldset, but is using a template. Fieldsets make no sense when using templates"); + + // All elements should have at least the title key set + if (!isset($element['title'])) { + $element['title'] = ''; } - $this->include_plugin('element', 'fieldset'); - foreach ($element['elements'] as $subname => &$subelement) { - // The name can be in the element itself. This is compatibility for the perl version - if (isset($subelement['name'])) { - $subname = $subelement['name']; - } - if (count($subelement) == 0) { - throw new PieformException('An element in form "' . $this->name . '" has no data (' . $subname . ')'); - } - if (!isset($subelement['type'])) { - $subelement['type'] = 'markup'; - if (!isset($subelement['value'])) { - throw new PieformException('The markup element "' - . $name . '" has no value'); - } - } - // Configure some basics for real elements - if ($subelement['type'] != 'markup') { - // This function can be defined by the application using Pieforms, - // and applies to all elements of this type - $function = 'pieform_element_' . $subelement['type'] . '_configure'; - if (function_exists($function)) { - $subelement = $function($subelement); - } - - // This function is defined by the plugin itself, to set fields on - // the element that need to be set but should not be set by the - // application - $function = 'pieform_element_' . $subelement['type'] . '_set_attributes'; - $this->include_plugin('element', $subelement['type']); - if (function_exists($function)) { - $subelement = $function($subelement); - } - - // Add the autofocus flag to the element if required - if (!$autofocusadded && $this->data['autofocus'] === true && empty($element['nofocus'])) { - $subelement['autofocus'] = true; - $autofocusadded = true; - } - else if (!empty($this->data['autofocus']) && $this->data['autofocus'] !== true - && $subname == $this->data['autofocus']) { - $subelement['autofocus'] = true; - } - - // All elements should have some kind of title - if (!isset($subelement['title'])) { - $subelement['title'] = ''; - } - - // Force the form method to post if there is a file to upload. - if ($subelement['type'] == 'file') { - $this->fileupload = true; - if ($this->data['method'] == 'get') { - $this->data['method'] = 'post'; - self::info("Your form '$this->name' had the method 'get' and also a file element - it has been converted to 'post'"); - } - } - - // All elements inherit the form tabindex - $subelement['tabindex'] = $this->data['tabindex']; + // Force the form method to post if there is a file to upload + if ($element['type'] == 'file') { + $this->fileupload = true; + if ($this->data['method'] == 'get') { + $this->data['method'] = 'post'; + self::info("Your form '$this->name' had the method 'get' and also a file element - it has been converted to 'post'"); } - $subelement['name'] = $subname; + } + // This function can be defined by the application using Pieforms, + // and applies to all elements of this type + $function = 'pieform_element_' . $element['type'] . '_configure'; + if (function_exists($function)) { + $element = $function($element); } - } - else { - // Let each element set and override attributes if necessary - if ($element['type'] != 'markup') { - $function = 'pieform_element_' . $element['type'] . '_configure'; - if (function_exists($function)) { - $element = $function($element); - } - $function = 'pieform_element_' . $element['type'] . '_set_attributes'; - $this->include_plugin('element', $element['type']); - if (function_exists($function)) { - $element = $function($element); - } + // vvv --------------------------------------------------- vvv + // After this point Pieforms can set or override attributes + // without fear that the developer will be able to change them. - // Add the autofocus flag to the element if required - if (!$autofocusadded && $this->data['autofocus'] === true && empty($element['nofocus'])) { - $element['autofocus'] = true; - $autofocusadded = true; - } - elseif (!empty($this->data['autofocus']) && $this->data['autofocus'] !== true - && $name == $this->data['autofocus']) { - $element['autofocus'] = true; - } + // This function is defined by the plugin itself, to set + // fields on the element that need to be set but should not + // be set by the application + $function = 'pieform_element_' . $element['type'] . '_set_attributes'; + if (function_exists($function)) { + $element = $function($element); + } - $element['tabindex'] = $this->data['tabindex']; + // Add the autofocus flag to the element if required + if (!$autofocusadded && $this->data['autofocus'] === true && empty($element['nofocus'])) { + $element['autofocus'] = true; + $autofocusadded = true; } - $element['name'] = $name; - } + elseif (!empty($this->data['autofocus']) && $this->data['autofocus'] !== true + && $name == $this->data['autofocus']) { + $element['autofocus'] = true; + } + // All elements inherit the form tabindex + $element['tabindex'] = $this->data['tabindex']; + } + $element['name'] = $name; } // Check if the form was submitted, and if so, validate and process it @@ -528,7 +495,7 @@ // Submit the form if things went OK if ($this->data['submit'] && !$this->has_errors()) { $submitted = false; - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if (!empty($element['submitelement']) && isset($global[$element['name']])) { $function = "{$this->data['successcallback']}_{$element['name']}"; if (function_exists($function)) { @@ -543,10 +510,8 @@ // Call the user defined function for processing a submit // This function should really redirect/exit after it has // finished processing the form. - // @todo maybe it should do just that... call_user_func_array($function, array($this, $values)); if ($this->data['dieaftersubmit']) { - // This will only work if I can make the login_submit function stuff work in login_validate if ($this->data['jsform']) { $message = 'Your ' . $this->name . '_submit function should use $form->json_reply to send a response'; } @@ -565,6 +530,8 @@ } } + // If we get here, the form was submitted but failed validation + // Auto focus the first element with an error if required if ($this->data['autofocus'] !== false) { $this->auto_focus_first_error(); @@ -642,9 +609,10 @@ }/*}}}*/ /** - * Builds and returns the HTML for the form, respecting the chosen renderer. + * Builds and returns the HTML for the form, using the chosen renderer or + * template * - * Note that the "action" attribute for the form tag are NOT HTML escaped + * Note that the "action" attribute for the form tag is NOT HTML escaped * for you. This allows you to build your own URLs, should you require. On * the other hand, this means you must be careful about escaping the URL, * especially if it has data from an external source in it. @@ -675,7 +643,7 @@ // $elements is a convenience variable that contains all of the form elements (minus fieldsets and // hidden elements) $elements = array(); - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if ($element['type'] != 'hidden') { $elements[$element['name']] = $element; } @@ -684,7 +652,7 @@ // Hidden elements $this->include_plugin('element', 'hidden'); $hidden_elements = ''; - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if ($element['type'] == 'hidden') { $hidden_elements .= pieform_element_hidden($this, $element); } @@ -743,7 +711,7 @@ // Hidden elements $this->include_plugin('element', 'hidden'); - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if ($element['type'] == 'hidden') { $result .= pieform_element_hidden($this, $element); } @@ -828,7 +796,7 @@ } return $elements; }/*}}}*/ - + /** * Returns the element with the given name. Throws a PieformException if the * element cannot be found. @@ -841,11 +809,10 @@ * @throws PieformException If the element could not be found */ public function get_element($name) {/*{{{*/ - foreach ($this->get_elements() as $element) { - if ($element['name'] == $name) { - return $element; - } + if (isset($this->elementrefs[$name])) { + return $this->elementrefs[$name]; } + throw new PieformException('Element "' . $name . '" cannot be found'); }/*}}}*/ @@ -864,7 +831,7 @@ private function get_submitted_values() {/*{{{*/ $result = array(); $global = ($this->data['method'] == 'get') ? $_GET : $_POST; - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if ($element['type'] != 'markup') { if ( (empty($element['submitelement']) && empty($element['cancelelement'])) || @@ -900,7 +867,7 @@ } // Perform rule validation - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if (isset($element['rules']) && is_array($element['rules'])) { foreach ($element['rules'] as $rule => $data) { if (!$this->get_error($element['name'])) { @@ -936,7 +903,7 @@ $result = "var {$this->name}_btn = null;\n"; $connecteventadded = false; - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if (!empty($element['submitelement'])) { if (!$connecteventadded) { $result .= "addLoadEvent(function() {\n"; @@ -1244,7 +1211,7 @@ * @return bool Whether there are errors with the form */ public function has_errors() {/*{{{*/ - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if (isset($element['error'])) { return true; } @@ -1371,7 +1338,7 @@ */ public function get_errors() {/*{{{*/ $result = array(); - foreach ($this->get_elements() as $element) { + foreach ($this->elementrefs as $element) { if (isset($element['error'])) { $result[] = $element; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 01:59:48
|
Revision: 253 http://pieforms.svn.sourceforge.net/pieforms/?rev=253&view=rev Author: oracleshinoda Date: 2007-12-30 17:59:52 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Remove an unneeded variable. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 01:59:27 UTC (rev 252) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 01:59:52 UTC (rev 253) @@ -294,11 +294,10 @@ // when displaying errors 'showdescriptiononerror' => true, ); - $data = array_merge($formdefaults, $formconfig, $data); - $this->data = $data; + $this->data = array_merge($formdefaults, $formconfig, $data); // Set the method - only get/post allowed - $this->data['method'] = strtolower($data['method']); + $this->data['method'] = strtolower($this->data['method']); if ($this->data['method'] != 'post') { $this->data['method'] = 'get'; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 01:59:23
|
Revision: 252 http://pieforms.svn.sourceforge.net/pieforms/?rev=252&view=rev Author: oracleshinoda Date: 2007-12-30 17:59:27 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Foldmarkers, better commenting, and other fixes. * Updated copyright to 2008 * Added foldmarkers to all methods/functions, using vim's 'vf' * Improved the json_encode replacement, so if the json extension is not loaded and json_encode is never used, you don't have to have the replacement Services_JSON all set up * Updated a few function/method comments for spelling, removing references to Mahara or marking functions for deletion. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-31 01:58:57 UTC (rev 251) +++ pieforms-php5/trunk/src/pieform.php 2007-12-31 01:59:27 UTC (rev 252) @@ -20,7 +20,7 @@ * @subpackage core * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -44,7 +44,6 @@ * <pre> * $form = array( * 'name' => 'myform', - * 'action' => 'myscript.php', * 'method' => 'post', * 'elements' => array( * // definition of elements in the form @@ -64,37 +63,25 @@ * } * </pre> * - * Please see https://eduforge.org/wiki/wiki/mahara/wiki?pagename=FormAPI for + * Please see http://pieforms.sourceforge.net/doc/html/ for * more information on creating and using forms. * */ -function pieform($data) { // {{{ +function pieform($data) {/*{{{*/ return Pieform::process($data); - // - // @todo stuff to do for forms: - // - // - more form element types (inc. types like autocomplete and wyswiyg) - // - support processing of data before validation occurs (e.g. trim(), strtoupper()) - // - Basic validation is possible as there's a callback function for checking, - // but some helper functions could be written to make people's job validating - // stuff much easier (form_validate_email, form_validate_date etc). - // - Collapsible js for fieldsets - // - Grippie for textareas - // - handle multipage forms? - // - handle a tabbed interface type of form? - // -} // }}} +}/*}}}*/ -if (!function_exists('json_encode')) { - require_once 'JSON/JSON.php'; +// json_encode replacement, if the user doesn't have this function available +if (!function_exists('json_encode')) {/*{{{*/ function json_encode($data) { + require_once 'JSON/JSON.php'; $json = new Services_JSON(); return $json->encode($data); } -} +}/*}}}*/ /** - * Pieform throws PieformExceptions, so you can catch them specifically + * Pieforms throws PieformExceptions when things go wrong */ class PieformException extends Exception {} @@ -107,11 +94,11 @@ * functions. * * For more information on how Pieforms works, please see the documentation - * at https://eduforge.org/wiki/wiki/mahara/wiki?pagename=FormAPI + * at http://pieforms.sourceforge.net/doc/html/ */ -class Pieform { // {{{ +class Pieform {/*{{{*/ - // {{{ Fields + /*{{{ Fields */ /** * Maintains a tab index across all created forms, to make it easy for @@ -151,21 +138,21 @@ * @var bool */ private $submitted = false; + + /*}}}*/ - // }}} - /** * Processes the form. Called by the {@link pieform} function. It simply * builds the form (processing it if it has been submitted), and returns - * the HTML to display the form + * the HTML to display the form. * * @param array $data The form description hash * @return string The HTML representing the form */ - public static function process($data) { // {{{ + public static function process($data) {/*{{{*/ $form = new Pieform($data); return $form->build(); - } // }}} + }/*}}}*/ /** * Sets the attributes of the form according to the passed data, performing @@ -174,7 +161,7 @@ * * @param array $data The form description hash */ - public function __construct($data) { // {{{ + public function __construct($data) {/*{{{*/ $GLOBALS['_PIEFORM_REGISTRY'][] = $this; if (!isset($data['name']) || !preg_match('/^[a-z_][a-z0-9_]*$/', $data['name'])) { @@ -601,47 +588,48 @@ $this->json_reply(PIEFORM_ERR, array('message' => $message, 'errors' => $json)); } } - } // }}} + }/*}}}*/ /** + * Returns the form name + * + * @return string + */ + public function get_name() {/*{{{*/ + return $this->name; + }/*}}}*/ + + /** * Returns a generic property. This can be used to retrieve any property * set in the form data array, so developers can pass in random stuff and * get access to it. * - * @param string The key of the property to return + * @param string The key of the property to return. If the property doesn't + * exist, null is returned * @return mixed */ - public function get_property($key) { // {{{ + public function get_property($key) {/*{{{*/ if (array_key_exists($key, $this->data)) { return $this->data[$key]; } return null; - } // }}} + }/*}}}*/ /** - * Returns the form name - * - * @return string - */ - public function get_name() { // {{{ - return $this->name; - } // }}} - - /** * Returns whether the form has been submitted * * @return bool */ - public function is_submitted() { + public function is_submitted() {/*{{{*/ return $this->submitted; - } + }/*}}}*/ /** * Returns the HTML for the <form...> tag * * @return string */ - public function get_form_tag() { + public function get_form_tag() {/*{{{*/ $result = '<form class="pieform"'; foreach (array('name', 'method', 'action') as $attribute) { $result .= ' ' . $attribute . '="' . $this->data[$attribute] . '"'; @@ -652,7 +640,7 @@ } $result .= '>'; return $result; - } + }/*}}}*/ /** * Builds and returns the HTML for the form, respecting the chosen renderer. @@ -665,7 +653,7 @@ * @param boolean Whether to include the <form...></form> tags in the output * @return string The form as HTML */ - public function build($outputformtags=true) { + public function build($outputformtags=true) {/*{{{*/ $result = ''; // Builds the HTML each element (see the build_element_html method for @@ -790,7 +778,7 @@ } return $result; - } + }/*}}}*/ /** * Given an element, gets the value for it from this form @@ -799,7 +787,7 @@ * @return mixed The element's value. <kbd>null</kbd> if no value * is available for the element. */ - public function get_value($element) { + public function get_value($element) {/*{{{*/ $function = 'pieform_element_' . $element['type'] . '_get_value'; if (function_exists($function)) { return $function($this, $element); @@ -818,7 +806,7 @@ return $element['defaultvalue']; } return null; - } + }/*}}}*/ /** * Retrieves a list of elements in the form. @@ -827,7 +815,7 @@ * * @return array The elements of the form */ - public function get_elements() { + public function get_elements() {/*{{{*/ $elements = array(); foreach ($this->data['elements'] as $name => $element) { if ($element['type'] == 'fieldset') { @@ -840,7 +828,7 @@ } } return $elements; - } + }/*}}}*/ /** * Returns the element with the given name. Throws a PieformException if the @@ -853,14 +841,14 @@ * @return array The element * @throws PieformException If the element could not be found */ - public function get_element($name) { + public function get_element($name) {/*{{{*/ foreach ($this->get_elements() as $element) { if ($element['name'] == $name) { return $element; } } throw new PieformException('Element "' . $name . '" cannot be found'); - } + }/*}}}*/ /** * Retrieves submitted values from the request for the elements of this form. @@ -874,7 +862,7 @@ * * @return array The submitted values */ - private function get_submitted_values() { + private function get_submitted_values() {/*{{{*/ $result = array(); $global = ($this->data['method'] == 'get') ? $_GET : $_POST; foreach ($this->get_elements() as $element) { @@ -891,7 +879,7 @@ } } return $result; - } + }/*}}}*/ /** * Performs simple validation based off the definition array. @@ -906,7 +894,7 @@ * * @param array $values The submitted values from the form */ - private function validate($values) { + private function validate($values) {/*{{{*/ // Call the overall validation function if it is available if (function_exists('pieform_validate')) { pieform_validate($this, $values); @@ -943,9 +931,9 @@ if (is_callable($function)) { call_user_func_array($function, array($this, $values)); } - } + }/*}}}*/ - private function whichbutton_js() { + private function whichbutton_js() {/*{{{*/ $result = "var {$this->name}_btn = null;\n"; $connecteventadded = false; @@ -969,7 +957,7 @@ } return $result; - } + }/*}}}*/ /** * Builds the javascript for submitting the form. Note that the iframe is @@ -977,7 +965,7 @@ * display: none. Positioning it absolute and 'hidden' has the same effect * without the breakage. */ - private function submit_js() { + private function submit_js() {/*{{{*/ $result = <<<EOF connect($('{$this->name}'), 'onsubmit', function(e) { if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } @@ -1077,9 +1065,9 @@ } return $result . $function($this->name); - } + }/*}}}*/ - public function json_reply($returncode, $message=null) { + public function json_reply($returncode, $message=null) {/*{{{*/ $data = array( 'returnCode' => intval($returncode), 'message' => $message @@ -1090,7 +1078,7 @@ <html><head><script type="text/javascript">function sendResult() { parent.pieformHandler_{$this->name}($result); }</script></head><body onload="sendResult(); "></body></html> EOF; exit; - } + }/*}}}*/ /** * Returns whether a field has an error marked on it. @@ -1110,10 +1098,10 @@ * @return bool Whether the element has an error * @throws PieformException If the element could not be found */ - public function get_error($name) { + public function get_error($name) {/*{{{*/ $element = $this->get_element($name); return isset($element['error']); - } + }/*}}}*/ /** * Marks a field has having an error. @@ -1121,14 +1109,11 @@ * This method should be used to set an error on an element in a custom * validation function, if one has occured. * - * Note that for the Mahara project, your error messages must be passed - * through {@link get_string} to internationalise them. - * * @param string $name The name of the element to set an error on * @param string $message The error message * @throws PieformException If the element could not be found */ - public function set_error($name, $message) { + public function set_error($name, $message) {/*{{{*/ foreach ($this->data['elements'] as &$element) { if ($element['type'] == 'fieldset') { foreach ($element['elements'] as &$subelement) { @@ -1146,7 +1131,7 @@ } } throw new PieformException('Element "' . $name . '" could not be found'); - } + }/*}}}*/ /** * Makes an ID for an element. @@ -1155,12 +1140,12 @@ * an element gets an ID. * * The element's existing 'id' and 'name' attributes are checked first. If - * they are not specified, a random ID is synthesised + * they are not specified, a random ID is created * * @param array $element The element to make an ID for * @return string The ID for the element */ - public function make_id($element) { + public function make_id($element) {/*{{{*/ if (isset($element['id'])) { return self::hsc($element['id']); } @@ -1168,7 +1153,7 @@ return self::hsc($element['name']); } return substr(md5(mt_rand()), 0, 4); - } + }/*}}}*/ /** * Makes a class for an element. @@ -1182,7 +1167,7 @@ * @param array $element The element to make a class for * @return string The class for an element */ - public function make_class($element) { + public function make_class($element) {/*{{{*/ $classes = array(); if (isset($element['class'])) { $classes[] = $element['class']; @@ -1198,12 +1183,12 @@ } // Please make sure that 'autofocus' is the last class added in this // method. Otherwise, improve the logic for removing 'autofocus' from - // the elemnt class string in pieform_render_element + // the element class string in pieform_render_element if (!empty($element['autofocus'])) { $classes[] = 'autofocus'; } return implode(' ', $classes); - } + }/*}}}*/ /** * Given an element, returns a string representing the basic attribute @@ -1228,7 +1213,7 @@ * @param array $exclude Any attributes to explicitly exclude from adding * @return string The attributes for the element */ - public function element_attributes($element, $exclude=array()) { + public function element_attributes($element, $exclude=array()) {/*{{{*/ static $attributes = array('accesskey', 'class', 'dir', 'id', 'lang', 'name', 'onclick', 'size', 'style', 'tabindex'); $elementattributes = array_diff($attributes, $exclude); $result = ''; @@ -1252,21 +1237,21 @@ } return $result; - } + }/*}}}*/ /** * Checks if there are errors on any of the form elements. * * @return bool Whether there are errors with the form */ - public function has_errors() { + public function has_errors() {/*{{{*/ foreach ($this->get_elements() as $element) { if (isset($element['error'])) { return true; } } return false; - } + }/*}}}*/ /** * Includes a plugin file, checking any configured plugin directories. @@ -1275,7 +1260,7 @@ * @param string $name The name of the plugin to include * @throws PieformException If the given type or plugin could not be found */ - public function include_plugin($type, $name) { + public function include_plugin($type, $name) {/*{{{*/ if (!in_array($type, array('element', 'renderer', 'rule'))) { throw new PieformException("The type \"$type\" is not allowed for an include plugin"); } @@ -1297,7 +1282,7 @@ } throw new PieformException("Could not find $type \"$name\""); - } + }/*}}}*/ /** * Return an internationalised string based on the passed input key @@ -1312,7 +1297,7 @@ * can specify there own i18n strings for rules * @return string The internationalised string */ - public function i18n($plugin, $pluginname, $key, $element) { + public function i18n($plugin, $pluginname, $key, $element) {/*{{{*/ if (!in_array($plugin, array('element', 'renderer', 'rule'))) { throw new PieformException("Invalid plugin name '$plugin'"); } @@ -1339,7 +1324,7 @@ // We don't recognise this string return '[[' . $key . ']]'; - } + }/*}}}*/ /** * HTML-escapes the given value @@ -1347,16 +1332,16 @@ * @param string $text The text to escape * @return string The text, HTML escaped */ - public static function hsc($text) { + public static function hsc($text) {/*{{{*/ return htmlspecialchars($text, ENT_COMPAT, 'UTF-8'); - } + }/*}}}*/ /** * Hook for giving information back to the developer * * @param string $message The message to give to the developer */ - public static function info($message) { + public static function info($message) {/*{{{*/ $function = 'pieform_info'; if (function_exists($function)) { $function($message); @@ -1364,20 +1349,20 @@ else { trigger_error($message, E_USER_NOTICE); } - } + }/*}}}*/ /** * Makes sure that the javascript callbacks for this form are valid javascript * function names. */ - private function validate_js_callbacks() { + private function validate_js_callbacks() {/*{{{*/ foreach (array('presubmitcallback', 'postsubmitcallback', 'jssuccesscallback', 'jserrorcallback', 'globaljserrorcallback') as $callback) { if ($this->data[$callback] != '' && !preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $this->data[$callback])) { throw new PieformException("'{$this->data[$callback]}' is not a valid javascript callback name for callback '$callback'"); } } - } + }/*}}}*/ /** * Returns elements with errors on them @@ -1385,7 +1370,7 @@ * @return array An array of elements with errors on them, the empty array * in the result of no errors. */ - public function get_errors() { + public function get_errors() {/*{{{*/ $result = array(); foreach ($this->get_elements() as $element) { if (isset($element['error'])) { @@ -1393,13 +1378,13 @@ } } return $result; - } + }/*}}}*/ /** * Sets the 'autofocus' property on the first element encountered that has * an error on it */ - private function auto_focus_first_error() { + private function auto_focus_first_error() {/*{{{*/ foreach ($this->data['elements'] as &$element) { if ($element['type'] == 'fieldset') { foreach ($element['elements'] as &$subelement) { @@ -1418,7 +1403,7 @@ unset($element['autofocus']); } } - } + }/*}}}*/ /** * Given an element, builds all of the HTML for it - for example, the label @@ -1433,7 +1418,7 @@ * * @param array &$element The element to build the HTML for */ - private function build_element_html(&$element) { + private function build_element_html(&$element) {/*{{{*/ // Set ID and class for elements $element['id'] = $this->make_id($element); $element['class'] = $this->make_class($element); @@ -1466,9 +1451,9 @@ $element['helphtml'] = '<span class="help"><a href="" title="' . Pieform::hsc($element['help']) . '" onclick="return false;">?</a></span>'; } } - } + }/*}}}*/ -} // }}} +}/*}}}*/ /** @@ -1484,11 +1469,14 @@ * {@internal This is separate so that child element types can nest other * elements inside them (like the fieldset element does for example).}} * + * NOTE: This function is SCHEDULED FOR REMOVAL. Nicer ways of getting built + * elements are available + * * @param Pieform $form The form to render the element for * @param array $element The element to render * @return string The rendered element */ -function pieform_render_element(Pieform $form, $element) { +function pieform_render_element(Pieform $form, $element) {/*{{{*/ // If the element is pure markup, don't pass it to the renderer if ($element['type'] == 'markup') { return $element['value'] . "\n"; @@ -1512,9 +1500,18 @@ } return $rendererfunction($form, $element); -} +}/*}}}*/ -function pieform_get_headdata() { +/** + * Returns an array of HTML elements to be placed in the <head> section of the + * page. + * + * This works for all forms that have been built at the time this function is + * called - so call this function after all forms are built! + * + * @return array + */ +function pieform_get_headdata() {/*{{{*/ $htmlelements = array(); foreach ($GLOBALS['_PIEFORM_REGISTRY'] as $form) { foreach ($form->get_elements() as $element) { @@ -1527,6 +1524,6 @@ } return array_unique($htmlelements); -} +}/*}}}*/ ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 01:58:59
|
Revision: 251 http://pieforms.svn.sourceforge.net/pieforms/?rev=251&view=rev Author: oracleshinoda Date: 2007-12-30 17:58:57 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Added foldmarkers. Updated copyright for 2008. Modified Paths: -------------- pieforms-php5/trunk/src/pieform/elements/fieldset.php Modified: pieforms-php5/trunk/src/pieform/elements/fieldset.php =================================================================== --- pieforms-php5/trunk/src/pieform/elements/fieldset.php 2007-12-31 01:58:28 UTC (rev 250) +++ pieforms-php5/trunk/src/pieform/elements/fieldset.php 2007-12-31 01:58:57 UTC (rev 251) @@ -20,7 +20,7 @@ * @subpackage element * @author Nigel McNie <ni...@ca...> * @license http://www.gnu.org/copyleft/gpl.html GNU GPL - * @copyright (C) 2006 Catalyst IT Ltd http://catalyst.net.nz + * @copyright (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz * */ @@ -32,7 +32,7 @@ * @param array $element The element to render * @return string The HTML for the element */ -function pieform_element_fieldset(Pieform $form, $element) { +function pieform_element_fieldset(Pieform $form, $element) { // {{{ $result = "\n<fieldset"; if (!empty($element['collapsible'])) { if (!isset($element['legend']) || $element['legend'] === '') { @@ -78,6 +78,6 @@ $result .= "</fieldset>\n"; return $result; -} +} // }}} ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-31 01:58:27
|
Revision: 250 http://pieforms.svn.sourceforge.net/pieforms/?rev=250&view=rev Author: oracleshinoda Date: 2007-12-30 17:58:28 -0800 (Sun, 30 Dec 2007) Log Message: ----------- Some more re-wording in the README to make a bit more sense. Modified Paths: -------------- pieforms-php5/trunk/README Modified: pieforms-php5/trunk/README =================================================================== --- pieforms-php5/trunk/README 2007-12-28 05:18:39 UTC (rev 249) +++ pieforms-php5/trunk/README 2007-12-31 01:58:28 UTC (rev 250) @@ -11,9 +11,9 @@ Pieforms provides a simple, unified way to create, validate and process web 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 whole form can be layed out as precisely as you like, -allowing a lot of flexibility around form output. +and ajax comboboxes. In addition, each element can have pluggable rules applied +to it, and the form can be layed out as consistently or flexibly as you +require. Pieforms also has a really simple API that makes writing forms very easy. For most cases, you will simply define a hash describing your form and provide a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-28 05:18:37
|
Revision: 249 http://pieforms.svn.sourceforge.net/pieforms/?rev=249&view=rev Author: oracleshinoda Date: 2007-12-27 21:18:39 -0800 (Thu, 27 Dec 2007) Log Message: ----------- More folding, more git checking. I think the property is called authorsfile, not authorsurl! Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-28 04:53:04 UTC (rev 248) +++ pieforms-php5/trunk/src/pieform.php 2007-12-28 05:18:39 UTC (rev 249) @@ -623,9 +623,9 @@ * * @return string */ - public function get_name() { + public function get_name() { // {{{ return $this->name; - } + } // }}} /** * Returns whether the form has been submitted This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |