[Pieforms-commit] SF.net SVN: pieforms: [32] pieforms/src/pieform.php
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2006-11-19 00:36:14
|
Revision: 32 http://svn.sourceforge.net/pieforms/?rev=32&view=rev Author: oracleshinoda Date: 2006-11-18 16:36:14 -0800 (Sat, 18 Nov 2006) Log Message: ----------- Generalised processingStart and processingStop to be configurable. Now validation of JS callback names is done. Properly i18n'd a couple of ajax related strings Modified Paths: -------------- pieforms/src/pieform.php Modified: pieforms/src/pieform.php =================================================================== --- pieforms/src/pieform.php 2006-11-18 13:04:32 UTC (rev 31) +++ pieforms/src/pieform.php 2006-11-19 00:36:14 UTC (rev 32) @@ -152,6 +152,21 @@ private $ajaxpost = false; /** + * A callback to call before submitting the form via AJAX + * + * @var string + */ + private $preajaxsubmitcallback = ''; + + /** + * A callback to call after submitting the form via AJAX, regardless of + * the result of the submission + * + * @var string + */ + private $postajaxsubmitcallback = ''; + + /** * Name of a javascript function to call on successful ajax submission * * @var string @@ -297,8 +312,10 @@ 'action' => '', 'onsubmit' => '', 'ajaxpost' => false, - 'ajaxsuccessfunction' => '', - 'ajaxfailurefunction' => '', + 'preajaxsubmitcallback' => '', + 'postajaxsubmitcallback' => '', + 'ajaxsuccessfunction' => '', + 'ajaxfailurefunction' => '', 'autofocus' => false, 'language' => 'en', 'validate' => true, @@ -338,8 +355,11 @@ if ($data['ajaxpost']) { $this->ajaxpost = true; - $this->ajaxsuccessfunction = $data['ajaxsuccessfunction']; - $this->ajaxfailurefunction = $data['ajaxfailurefunction']; + $this->preajaxsubmitcallback = self::validate_js_callback($data['preajaxsubmitcallback']); + $this->postajaxsubmitcallback = self::validate_js_callback($data['postajaxsubmitcallback']); + // @todo rename to *callback instead of *function for consistency + $this->ajaxsuccessfunction = self::validate_js_callback($data['ajaxsuccessfunction']); + $this->ajaxfailurefunction = self::validate_js_callback($data['ajaxfailurefunction']); } if (isset($data['renderer'])) { @@ -783,7 +803,11 @@ // Also should only save wysiwyg elements in the form, not all of them... if (typeof(tinyMCE) != 'undefined') { tinyMCE.triggerSave(); } - processingStart(); +EOF; + if (!empty($this->preajaxsubmitcallback)) { + $result .= " $this->preajaxsubmitcallback();\n"; + } + $result .= <<<EOF var data = {}; EOF; @@ -849,15 +873,14 @@ } } - $result .= <<<EOF + $result .= " }\n"; + if (!empty($this->postajaxsubmitcallback)) { + $result .= " $this->postajaxsubmitcallback();\n"; } - processingStop(); -EOF; - // @todo not with get_string! $this->i18n instead - $strunknownerror = get_string('unknownerror'); - $strprocessingform = get_string('processingform'); + $strunknownerror = $this->i18n('ajaxunknownerror'); + $strprocessingform = $this->i18n('processingform'); $result .= <<<EOF }, function() { @@ -1093,6 +1116,15 @@ } } + private static function validate_js_callback($name) { + if ($name == '') { + return ''; + } + if (!preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name)) { + throw new PieformException("'$name' is not a valid javascript callback name"); + } + } + /** * Returns elements with errors on them * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |