[Pieforms-commit] SF.net SVN: pieforms: [99] pieforms-php5/trunk/src/pieform.php
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2006-12-17 23:24:50
|
Revision: 99 http://svn.sourceforge.net/pieforms/?rev=99&view=rev Author: oracleshinoda Date: 2006-12-17 15:24:49 -0800 (Sun, 17 Dec 2006) Log Message: ----------- Be much smarter about which submit button is being sent through in ajax land. This prevents problems with all buttons being sent through and thus causing hiccups with the choice of submit function to call. It also conveniently makes sure that the status messages will always be displayed next to the correct button Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2006-12-15 01:30:15 UTC (rev 98) +++ pieforms-php5/trunk/src/pieform.php 2006-12-17 23:24:49 UTC (rev 99) @@ -889,6 +889,20 @@ // @todo nigel should disable all buttons on this form while the submit is happening $result = <<<EOF +var {$this->name}_btn = null; +// For each submit button, add a waffer thin flag +addLoadEvent(function () { + +EOF; + foreach ($this->get_elements() as $element) { + if (!empty($element['ajaxmessages'])) { + $result .= " connect($('{$this->name}_{$element['name']}'), 'onclick', function () { {$this->name}_btn = '{$element['name']}'; });\n"; + } + } + $result .= <<<EOF + +}); + connect($('{$this->name}'), 'onsubmit', function (e) { // eventually we should check input types for wysiwyg before doing this // Also should only save wysiwyg elements in the form, not all of them... @@ -904,24 +918,23 @@ EOF; // Get values for each element from the form via the DOM foreach ($this->get_elements() as $element) { - if ($element['type'] != 'markup') { - $function = 'pieform_get_value_js_' . $element['type']; - if (function_exists($function)) { - // @todo reverse parameter order for consistency, PieForm first - $result .= $function($element, $this); + // Submit elements will be handled later, as there could be more than one + if (empty($element['ajaxmessages'])) { + if ($element['type'] != 'markup') { + $function = 'pieform_get_value_js_' . $element['type']; + if (function_exists($function)) { + // @todo reverse parameter order for consistency, PieForm first + $result .= $function($element, $this); + } + else { + $result .= " data['" . $element['name'] . "'] = document.forms['$this->name'].elements['{$element['name']}'].value;\n"; + } } - else { - $result .= " data['" . $element['name'] . "'] = document.forms['$this->name'].elements['{$element['name']}'].value;\n"; - } - if (!empty($element['ajaxmessages'])) { - $messageelement = $element['name']; - } } } - if (!isset($messageelement)) { - throw new PieformException('At least one submit-type element is required for AJAX forms'); - } + // Add only the submit button that was clicked + $result .= " data['{$this->name}_' + {$this->name}_btn] = document.forms['$this->name'].elements['{$this->name}_' + {$this->name}_btn].value;\n"; // Add the hidden element for detecting form submission $result .= " data['pieform_{$this->name}'] = '';\n"; @@ -992,7 +1005,7 @@ } } - return $result . $js_messages_function($this->name, $messageelement); + return $result . $js_messages_function($this->name); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |