[Pieforms-commit] SF.net SVN: pieforms: [262] pieforms-php5/trunk/src
Status: Alpha
Brought to you by:
oracleshinoda
|
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.
|