Thread: [Pieforms-commit] SF.net SVN: pieforms: [162] pieforms-php5/trunk/src/pieform.php (Page 2)
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2007-01-07 20:40:23
|
Revision: 162 http://svn.sourceforge.net/pieforms/?rev=162&view=rev Author: oracleshinoda Date: 2007-01-07 12:40:21 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Fix whitespace on trunk Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-01-07 11:31:25 UTC (rev 161) +++ pieforms-php5/trunk/src/pieform.php 2007-01-07 20:40:21 UTC (rev 162) @@ -488,7 +488,8 @@ $this->json_reply(PIEFORM_CANCEL, $element['goto']); } header('HTTP/1.1 303 See Other'); - header('Location:' . $element['goto']); exit; + header('Location:' . $element['goto']); + exit; } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-01-07 21:06:04
|
Revision: 163 http://svn.sourceforge.net/pieforms/?rev=163&view=rev Author: oracleshinoda Date: 2007-01-07 13:05:58 -0800 (Sun, 07 Jan 2007) Log Message: ----------- Added support for calling a global validation function pieform_validate for every form. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-01-07 20:40:21 UTC (rev 162) +++ pieforms-php5/trunk/src/pieform.php 2007-01-07 21:05:58 UTC (rev 163) @@ -499,11 +499,6 @@ $values = $this->get_submitted_values(); // Perform general validation first $this->validate($values); - // Then user specific validation if a function is available for that - $function = $this->data['validatecallback']; - if (is_callable($function)) { - call_user_func_array($function, array($this, $values)); - } // Submit the form if things went OK if ($this->data['submit'] && !$this->has_errors()) { @@ -805,6 +800,12 @@ * @param array $values The submitted values from the form */ private function validate($values) { + // Call the overall validation function if it is available + if (function_exists('pieform_validate')) { + pieform_validate($this, $values); + } + + // Perform rule validation foreach ($this->get_elements() as $element) { if (isset($element['rules']) && is_array($element['rules'])) { foreach ($element['rules'] as $rule => $data) { @@ -829,6 +830,12 @@ } } } + + // Then user specific validation if a function is available for that + $function = $this->data['validatecallback']; + if (is_callable($function)) { + call_user_func_array($function, array($this, $values)); + } } private function whichbutton_js() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-01-11 09:42:13
|
Revision: 165 http://svn.sourceforge.net/pieforms/?rev=165&view=rev Author: oracleshinoda Date: 2007-01-11 01:42:12 -0800 (Thu, 11 Jan 2007) Log Message: ----------- Added 'elementclasses' option - if set, then each element is given a class matching the type of element that it is Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-01-07 21:12:16 UTC (rev 164) +++ pieforms-php5/trunk/src/pieform.php 2007-01-11 09:42:12 UTC (rev 165) @@ -285,7 +285,10 @@ 'rulei18n' => array(), // The tabindex for the form (managed automatically by Pieforms) - 'tabindex' => false + 'tabindex' => false, + + // Whether to add a class of the type of the element to each element + 'elementclasses' => false ); $data = array_merge($formdefaults, $formconfig, $data); $this->data = $data; @@ -1049,7 +1052,7 @@ * @param array $element The element to make an ID for * @return string The ID for the element */ - public static function make_id($element) { + public function make_id($element) { if (isset($element['id'])) { return self::hsc($element['id']); } @@ -1071,7 +1074,7 @@ * @param array $element The element to make a class for * @return string The class for an element */ - public static function make_class($element) { + public function make_class($element) { $classes = array(); if (isset($element['class'])) { $classes[] = $element['class']; @@ -1082,6 +1085,9 @@ if (!empty($element['error'])) { $classes[] = 'error'; } + if ($this->data['elementclasses']) { + $classes[] = $element['type']; + } // 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 @@ -1336,8 +1342,8 @@ throw new PieformException('No such form renderer function: "' . $rendererfunction . '"'); } - $element['id'] = Pieform::make_id($element); - $element['class'] = Pieform::make_class($element); + $element['id'] = $form->make_id($element); + $element['class'] = $form->make_class($element); $builtelement = $function($form, $element); // Remove the 'autofocus' class, because we only want it on the form input This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-01-20 08:03:37
|
Revision: 170 http://svn.sourceforge.net/pieforms/?rev=170&view=rev Author: oracleshinoda Date: 2007-01-20 00:03:36 -0800 (Sat, 20 Jan 2007) Log Message: ----------- Use the type of the element instead of the name when working out the custom rule function Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-01-20 08:03:05 UTC (rev 169) +++ pieforms-php5/trunk/src/pieform.php 2007-01-20 08:03:36 UTC (rev 170) @@ -815,7 +815,7 @@ if (!$this->get_error($element['name'])) { // See if this element has a function that describes // how this rule should apply to it - $function = 'pieform_element_' . $element['name'] . '_rule_' . $rule; + $function = 'pieform_element_' . $element['type'] . '_rule_' . $rule; if (!function_exists($function)) { // Try instead the default rule function $function = 'pieform_rule_' . $rule; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-04 22:39:59
|
Revision: 174 http://svn.sourceforge.net/pieforms/?rev=174&view=rev Author: oracleshinoda Date: 2007-02-04 14:39:59 -0800 (Sun, 04 Feb 2007) Log Message: ----------- Fixed the form submission support under safari, by hiding the iframe instead of removing it. Try to normalise the names of the elements if possible (although this does not check inside fieldsets and needs some work) Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-02-04 22:38:38 UTC (rev 173) +++ pieforms-php5/trunk/src/pieform.php 2007-02-04 22:39:59 UTC (rev 174) @@ -325,6 +325,22 @@ throw new PieformException('Forms must have a list of elements'); } + // Rename all the keys to have nice compliant names + // @todo: + // - This isn't done for elements inside fieldsets + // - There's no easy way for other things do do all this preprocessing if they + // need. It should be a method so that other things (like multirecord) + // can use it. + $elements = array(); + foreach ($this->data['elements'] as $name => $element) { + $newname = preg_replace('/[^a-zA-Z0-9_]/', '_', $name); + if (isset($elements[$name])) { + throw new PieformException('Element "' . $name . '" has a dangerous name that interferes with another element'); + } + $elements[$newname] = $element; + } + $this->data['elements'] = $elements; + // Remove elements to ignore foreach ($this->data['elements'] as $name => $element) { if (isset($element['type']) && $element['type'] == 'fieldset') { @@ -867,6 +883,12 @@ return $result; } + /** + * Builds the javascript for submitting the form. Note that the iframe is + * not hidden with display: none, as safari/konqueror/ns6 ignore things with + * display: none. Positioning it absolute and 'hidden' has the same effect + * without the breakage. + */ private function submit_js() { $strprocessingform = get_string('processingform'); @@ -885,9 +907,9 @@ if (!iframe) { iframe = createDOM('iframe', { 'name': '{$this->name}_iframe', - 'id' : '{$this->name}_iframe' + 'id' : '{$this->name}_iframe', + 'style': 'position: absolute; visibility: hidden;' }); - hideElement(iframe); insertSiblingNodesAfter($('{$this->name}'), iframe); window.pieformHandler_{$this->name} = function(data) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-09 07:50:51
|
Revision: 177 http://svn.sourceforge.net/pieforms/?rev=177&view=rev Author: oracleshinoda Date: 2007-02-08 23:50:51 -0800 (Thu, 08 Feb 2007) Log Message: ----------- Removed call to get_string that is causing problems Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-02-04 23:00:03 UTC (rev 176) +++ pieforms-php5/trunk/src/pieform.php 2007-02-09 07:50:51 UTC (rev 177) @@ -890,8 +890,6 @@ * without the breakage. */ private function submit_js() { - $strprocessingform = get_string('processingform'); - $result = <<<EOF connect($('{$this->name}'), 'onsubmit', function(e) { if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-02-27 04:47:11
|
Revision: 191 http://svn.sourceforge.net/pieforms/?rev=191&view=rev Author: oracleshinoda Date: 2007-02-26 20:47:10 -0800 (Mon, 26 Feb 2007) Log Message: ----------- Merged Jeremy's fix to trunk Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-02-27 04:42:39 UTC (rev 190) +++ pieforms-php5/trunk/src/pieform.php 2007-02-27 04:47:10 UTC (rev 191) @@ -524,7 +524,7 @@ $submitted = false; foreach ($this->get_elements() as $element) { if (!empty($element['submitelement']) && isset($global[$element['name']])) { - $function = "{$this->name}_submit_{$element['name']}"; + $function = "{$this->data['successcallback']}_{$element['name']}"; if (function_exists($function)) { $function($this, $values); $submitted = true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-09-26 06:03:02
|
Revision: 220 http://pieforms.svn.sourceforge.net/pieforms/?rev=220&view=rev Author: oracleshinoda Date: 2007-09-25 23:03:04 -0700 (Tue, 25 Sep 2007) Log Message: ----------- Only output the button setting javascript if the form tags are being output, because it's the only time we can guarantee the dom node with the correct ID will be on the page Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-09-17 12:23:56 UTC (rev 219) +++ pieforms-php5/trunk/src/pieform.php 2007-09-26 06:03:04 UTC (rev 220) @@ -695,12 +695,14 @@ if ($this->data['jsform'] || $this->data['presubmitcallback']) { $result .= '<script type="text/javascript">'; - $result .= "\n" . $this->whichbutton_js(); + if ($outputformtags) { + $result .= "\n" . $this->whichbutton_js(); + } } if ($this->data['jsform']) { $result .= $this->submit_js(); } - else if ($this->data['presubmitcallback']) { + else if ($this->data['presubmitcallback'] && $outputformtags) { $result .= 'connect(\'' . $this->name . '\', \'onsubmit\', ' . 'function() { ' . $this->data['presubmitcallback'] . "('{$this->name}', {$this->name}_btn); });"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-12 21:40:56
|
Revision: 227 http://pieforms.svn.sourceforge.net/pieforms/?rev=227&view=rev Author: oracleshinoda Date: 2007-12-12 13:40:54 -0800 (Wed, 12 Dec 2007) Log Message: ----------- Apply patch from Mahara to make pieforms handle the case where a language string is asked for in a language we don't have a string for more gracefully. As reported by Nicolas Martignoni Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-08 01:20:39 UTC (rev 226) +++ pieforms-php5/trunk/src/pieform.php 2007-12-12 21:40:54 UTC (rev 227) @@ -1252,7 +1252,10 @@ $function = 'pieform_' . $plugin . '_' . $pluginname . '_i18n'; if (function_exists($function)) { $strings = $function(); - return $strings[$this->data['language']][$key]; + if (isset($strings[$this->data['language']][$key])) { + return $strings[$this->data['language']][$key]; + } + return '[[' . $key . '/' . $this->data['language'] . ']]'; } // We don't recognise this string This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-28 03:50:35
|
Revision: 243 http://pieforms.svn.sourceforge.net/pieforms/?rev=243&view=rev Author: oracleshinoda Date: 2007-12-27 19:50:40 -0800 (Thu, 27 Dec 2007) Log Message: ----------- Added fold markers for the pieform() function. In reality, I'm just checking to see if my author's map will work. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-28 00:32:52 UTC (rev 242) +++ pieforms-php5/trunk/src/pieform.php 2007-12-28 03:50:40 UTC (rev 243) @@ -68,7 +68,7 @@ * more information on creating and using forms. * */ -function pieform($data) { +function pieform($data) { // {{{ return Pieform::process($data); // // @todo stuff to do for forms: @@ -83,7 +83,7 @@ // - handle multipage forms? // - handle a tabbed interface type of form? // -} +} // }}} if (!function_exists('json_encode')) { require_once 'JSON/JSON.php'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-28 04:04:51
|
Revision: 244 http://pieforms.svn.sourceforge.net/pieforms/?rev=244&view=rev Author: oracleshinoda Date: 2007-12-27 20:04:53 -0800 (Thu, 27 Dec 2007) Log Message: ----------- Added some more foldmarkers. Still testing the git stuff. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2007-12-28 03:50:40 UTC (rev 243) +++ pieforms-php5/trunk/src/pieform.php 2007-12-28 04:04:53 UTC (rev 244) @@ -109,8 +109,10 @@ * For more information on how Pieforms works, please see the documentation * at https://eduforge.org/wiki/wiki/mahara/wiki?pagename=FormAPI */ -class Pieform { +class Pieform { // {{{ + // {{{ Fields + /** * Maintains a tab index across all created forms, to make it easy for * people to forget about it and have it just work for all of their forms. @@ -150,6 +152,8 @@ */ 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 @@ -1464,7 +1468,7 @@ } } -} +} // }}} /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-28 04:12:08
|
Revision: 245 http://pieforms.svn.sourceforge.net/pieforms/?rev=245&view=rev Author: oracleshinoda Date: 2007-12-27 20:12:11 -0800 (Thu, 27 Dec 2007) Log Message: ----------- More foldmarkers. And more testing of git stuff! 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:04:53 UTC (rev 244) +++ pieforms-php5/trunk/src/pieform.php 2007-12-28 04:12:11 UTC (rev 245) @@ -153,6 +153,7 @@ private $submitted = false; // }}} + // {{{ process() /** * Processes the form. Called by the {@link pieform} function. It simply @@ -167,6 +168,8 @@ return $form->build(); } + // }}} + /** * Sets the attributes of the form according to the passed data, performing * validation on the way. If the form is submitted, this checks and processes This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-28 04:23:54
|
Revision: 246 http://pieforms.svn.sourceforge.net/pieforms/?rev=246&view=rev Author: oracleshinoda Date: 2007-12-27 20:23:58 -0800 (Thu, 27 Dec 2007) Log Message: ----------- Moved foldmarkers for process() method. And still testing git stuff, of course! 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:12:11 UTC (rev 245) +++ pieforms-php5/trunk/src/pieform.php 2007-12-28 04:23:58 UTC (rev 246) @@ -153,7 +153,6 @@ private $submitted = false; // }}} - // {{{ process() /** * Processes the form. Called by the {@link pieform} function. It simply @@ -163,13 +162,11 @@ * @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 * validation on the way. If the form is submitted, this checks and processes This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-28 04:48:32
|
Revision: 247 http://pieforms.svn.sourceforge.net/pieforms/?rev=247&view=rev Author: oracleshinoda Date: 2007-12-27 20:48:37 -0800 (Thu, 27 Dec 2007) Log Message: ----------- Added more foldmarkers, testing more git stuff. 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:23:58 UTC (rev 246) +++ pieforms-php5/trunk/src/pieform.php 2007-12-28 04:48:37 UTC (rev 247) @@ -174,7 +174,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,7 +601,7 @@ $this->json_reply(PIEFORM_ERR, array('message' => $message, 'errors' => $json)); } } - } + } // }}} /** * Returns a generic property. This can be used to retrieve any property This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2007-12-28 04:53:00
|
Revision: 248 http://pieforms.svn.sourceforge.net/pieforms/?rev=248&view=rev Author: oracleshinoda Date: 2007-12-27 20:53:04 -0800 (Thu, 27 Dec 2007) Log Message: ----------- Another foldmarker, more git testing. 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:48:37 UTC (rev 247) +++ pieforms-php5/trunk/src/pieform.php 2007-12-28 04:53:04 UTC (rev 248) @@ -611,12 +611,12 @@ * @param string The key of the property to return * @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 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. |
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: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 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: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: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 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 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: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...> - 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. |