Thread: [Pieforms-commit] SF.net SVN: pieforms: [274] pieforms-php5/trunk/src/pieform.php (Page 3)
Status: Alpha
Brought to you by:
oracleshinoda
From: <ora...@us...> - 2008-01-03 09:10:23
|
Revision: 274 http://pieforms.svn.sourceforge.net/pieforms/?rev=274&view=rev Author: oracleshinoda Date: 2008-01-03 01:10:27 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Rename some reference loop variables now I know about the unset() trick. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2008-01-03 08:57:53 UTC (rev 273) +++ pieforms-php5/trunk/src/pieform.php 2008-01-03 09:10:27 UTC (rev 274) @@ -554,16 +554,18 @@ // Builds the HTML each element (see the build_element_html method for // more information) - foreach ($this->data['elements'] as &$elem) { - if ($elem['type'] == 'fieldset') { - foreach ($elem['elements'] as &$subelem) { - $this->build_element_html($subelem); + foreach ($this->data['elements'] as &$element) { + if ($element['type'] == 'fieldset') { + foreach ($element['elements'] as &$subelement) { + $this->build_element_html($subelement); } + unset($subelement); } else { - $this->build_element_html($elem); + $this->build_element_html($element); } } + unset($element); // If a template is to be used, use it instead of a renderer if (!empty($this->data['template'])) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2008-01-03 10:00:02
|
Revision: 276 http://pieforms.svn.sourceforge.net/pieforms/?rev=276&view=rev Author: oracleshinoda Date: 2008-01-03 02:00:07 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Re-ordered some methods in pieform.php so they're in a more logical order. Now private methods are all at the bottom, and all the error related methods are together. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2008-01-03 09:10:57 UTC (rev 275) +++ pieforms-php5/trunk/src/pieform.php 2008-01-03 10:00:07 UTC (rev 276) @@ -763,89 +763,6 @@ }/*}}}*/ /** - * Retrieves submitted values from the request for the elements of this form. - * - * This takes into account that some elements may not even have been set, - * for example if they were check boxes that were not checked upon - * submission. - * - * A value is returned for every element (except fieldsets of course). If - * an element was not set, the value set is <kbd>null</kbd>. - * - * @return array The submitted values - */ - private function get_submitted_values() {/*{{{*/ - $result = array(); - $global = ($this->data['method'] == 'get') ? $_GET : $_POST; - foreach ($this->elementrefs as $element) { - if ($element['type'] != 'markup') { - if ( - (empty($element['submitelement']) && empty($element['cancelelement'])) || - ( - (!empty($element['submitelement']) || !empty($element['cancelelement'])) - && isset($global[$element['name']]) - ) - ) { - $result[$element['name']] = $this->get_value($element); - } - } - } - return $result; - }/*}}}*/ - - /** - * Performs simple validation based off the definition array. - * - * Rules can be added to <kbd>pieform/rules/</kbd> directory, and then - * re-used in the 'rules' index of each element in the form definition - * hash. - * - * More complicated validation is possible by defining an optional - * callback with the name {$form->name}_validate. See the documentation for - * more information. - * - * @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->elementrefs as $element) { - if (isset($element['rules']) && is_array($element['rules'])) { - foreach ($element['rules'] as $rule => $data) { - 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['type'] . '_rule_' . $rule; - if (!function_exists($function)) { - // Try instead the default rule function - $function = 'pieform_rule_' . $rule; - if (!function_exists($function)) { - $this->include_plugin('rule', $rule); - if (!function_exists($function)) { - throw new PieformException('No such form rule "' . $rule . '"'); - } - } - } - if ($error = $function($this, $values[$element['name']], $element, $data)) { - $this->set_error($element['name'], $error); - } - } - } - } - } - - // 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)); - } - }/*}}}*/ - - /** * Sends a message back to a jsform. * * The message can contain almost any data, although how it is used is up to @@ -937,6 +854,36 @@ }/*}}}*/ /** + * Checks if there are errors on any of the form elements. + * + * @return bool Whether there are errors with the form + */ + public function has_errors() {/*{{{*/ + foreach ($this->elementrefs as $element) { + if (isset($element['error'])) { + return true; + } + } + return false; + }/*}}}*/ + + /** + * Returns elements with errors on them + * + * @return array An array of elements with errors on them, the empty array + * in the result of no errors. + */ + public function get_errors() {/*{{{*/ + $result = array(); + foreach ($this->elementrefs as $element) { + if (isset($element['error'])) { + $result[] = $element; + } + } + return $result; + }/*}}}*/ + + /** * Makes an ID for an element. * * Element IDs are used for <label>s, so use this method to ensure that @@ -1043,20 +990,6 @@ }/*}}}*/ /** - * Checks if there are errors on any of the form elements. - * - * @return bool Whether there are errors with the form - */ - public function has_errors() {/*{{{*/ - foreach ($this->elementrefs as $element) { - if (isset($element['error'])) { - return true; - } - } - return false; - }/*}}}*/ - - /** * Includes a plugin file, checking any configured plugin directories. * * @param string $type The type of plugin to include: 'element', 'renderer' or 'rule' @@ -1168,22 +1101,89 @@ }/*}}}*/ /** - * Returns elements with errors on them + * Retrieves submitted values from the request for the elements of this form. * - * @return array An array of elements with errors on them, the empty array - * in the result of no errors. + * This takes into account that some elements may not even have been set, + * for example if they were check boxes that were not checked upon + * submission. + * + * A value is returned for every element (except fieldsets of course). If + * an element was not set, the value set is <kbd>null</kbd>. + * + * @return array The submitted values */ - public function get_errors() {/*{{{*/ + private function get_submitted_values() {/*{{{*/ $result = array(); + $global = ($this->data['method'] == 'get') ? $_GET : $_POST; foreach ($this->elementrefs as $element) { - if (isset($element['error'])) { - $result[] = $element; + if ($element['type'] != 'markup') { + if ( + (empty($element['submitelement']) && empty($element['cancelelement'])) || + ( + (!empty($element['submitelement']) || !empty($element['cancelelement'])) + && isset($global[$element['name']]) + ) + ) { + $result[$element['name']] = $this->get_value($element); + } } } return $result; }/*}}}*/ /** + * Performs simple validation based off the definition array. + * + * Rules can be added to <kbd>pieform/rules/</kbd> directory, and then + * re-used in the 'rules' index of each element in the form definition + * hash. + * + * More complicated validation is possible by defining an optional + * callback with the name {$form->name}_validate. See the documentation for + * more information. + * + * @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->elementrefs as $element) { + if (isset($element['rules']) && is_array($element['rules'])) { + foreach ($element['rules'] as $rule => $data) { + 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['type'] . '_rule_' . $rule; + if (!function_exists($function)) { + // Try instead the default rule function + $function = 'pieform_rule_' . $rule; + if (!function_exists($function)) { + $this->include_plugin('rule', $rule); + if (!function_exists($function)) { + throw new PieformException('No such form rule "' . $rule . '"'); + } + } + } + if ($error = $function($this, $values[$element['name']], $element, $data)) { + $this->set_error($element['name'], $error); + } + } + } + } + } + + // 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)); + } + }/*}}}*/ + + /** * Sets the 'autofocus' property on the first element encountered that has * an error on it */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ora...@us...> - 2008-01-03 10:32:53
|
Revision: 277 http://pieforms.svn.sourceforge.net/pieforms/?rev=277&view=rev Author: oracleshinoda Date: 2008-01-03 02:32:58 -0800 (Thu, 03 Jan 2008) Log Message: ----------- Renamed the 'jsincludepath' configuration parameter to 'jsdirectory', which makes a little more sense to me. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2008-01-03 10:00:07 UTC (rev 276) +++ pieforms-php5/trunk/src/pieform.php 2008-01-03 10:32:58 UTC (rev 277) @@ -1313,7 +1313,7 @@ // The URL where pieforms.js and other related pieforms javascript // files can be accessed. Best specified as an absolute path in // pieform_configure() - 'jsincludepath' => '', + 'jsdirectory' => '', // The javascript function called before submission of a form // (regardless of whether the form is a jsform) @@ -1452,11 +1452,11 @@ } } - // TODO: jsincludepath should be independent of ANY form + // TODO: jsdirectory should be independent of ANY form array_unshift($htmlelements, '<script type="text/javascript" src="' - . Pieform::hsc($form->get_property('jsincludepath')) . 'pieforms.js"></script>'); + . Pieform::hsc($form->get_property('jsdirectory')) . 'pieforms.js"></script>'); array_unshift($htmlelements, '<script type="text/javascript">pieformPath = "' - . Pieform::hsc($form->get_property('jsincludepath')) . '";</script>'); + . Pieform::hsc($form->get_property('jsdirectory')) . '";</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...> - 2008-01-29 04:22:43
|
Revision: 281 http://pieforms.svn.sourceforge.net/pieforms/?rev=281&view=rev Author: oracleshinoda Date: 2008-01-28 20:22:47 -0800 (Mon, 28 Jan 2008) Log Message: ----------- Some whitespace/spelling fixes. Prevent the markup element causing fatal errors. Prevent calling pieform_get_headdata() with no forms causing a fatal error. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2008-01-03 10:59:30 UTC (rev 280) +++ pieforms-php5/trunk/src/pieform.php 2008-01-29 04:22:47 UTC (rev 281) @@ -155,7 +155,7 @@ * @var bool */ private $submitted_by_js = false; - + /*}}}*/ /** @@ -620,7 +620,7 @@ } $this->include_plugin('renderer', $this->data['renderer']); - + // Form header $function = 'pieform_renderer_' . $this->data['renderer'] . '_header'; if (function_exists($function)) { @@ -662,7 +662,7 @@ // 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 + // still active in the document // 2) The form is NOT a JS form, but has a presubmitcallback if (($this->data['jsform'] && !$this->submitted) || (!$this->data['jsform'] && $this->data['presubmitcallback'])) { @@ -1226,6 +1226,11 @@ $element['id'] = $this->make_id($element); $element['class'] = $this->make_class($element); + // If the element is pure markup, don't pass it to the renderer + if ($element['type'] == 'markup') { + return $element['value'] . "\n"; + } + // Build the element html $function = 'pieform_element_' . $element['type']; $element['html'] = $function($this, $element); @@ -1453,10 +1458,12 @@ } // TODO: jsdirectory should be independent of ANY form - array_unshift($htmlelements, '<script type="text/javascript" src="' - . Pieform::hsc($form->get_property('jsdirectory')) . 'pieforms.js"></script>'); - array_unshift($htmlelements, '<script type="text/javascript">pieformPath = "' - . Pieform::hsc($form->get_property('jsdirectory')) . '";</script>'); + if ($GLOBALS['_PIEFORM_REGISTRY']) { + array_unshift($htmlelements, '<script type="text/javascript" src="' + . Pieform::hsc($form->get_property('jsdirectory')) . 'pieforms.js"></script>'); + array_unshift($htmlelements, '<script type="text/javascript">pieformPath = "' + . Pieform::hsc($form->get_property('jsdirectory')) . '";</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...> - 2008-01-30 02:33:25
|
Revision: 288 http://pieforms.svn.sourceforge.net/pieforms/?rev=288&view=rev Author: oracleshinoda Date: 2008-01-29 18:33:29 -0800 (Tue, 29 Jan 2008) Log Message: ----------- Added a new method, 'reply', to handle JSON replying or calling a PHP reply callback. I'm sure this feature is badly designed and needs work, but it's in Mahara for now. Modified Paths: -------------- pieforms-php5/trunk/src/pieform.php Modified: pieforms-php5/trunk/src/pieform.php =================================================================== --- pieforms-php5/trunk/src/pieform.php 2008-01-29 04:27:29 UTC (rev 287) +++ pieforms-php5/trunk/src/pieform.php 2008-01-30 02:33:29 UTC (rev 288) @@ -222,6 +222,10 @@ $this->data['successcallback'] = $this->name . '_submit'; } + if (!$this->data['replycallback']) { + $this->data['replycallback'] = $this->name . '_reply'; + } + $this->data['configdirs'] = array_map( create_function('$a', 'return substr($a, -1) == "/" ? substr($a, 0, -1) : $a;'), (array) $this->data['configdirs']); @@ -426,7 +430,7 @@ call_user_func_array($function, array($this, $values)); if ($this->data['dieaftersubmit']) { if ($this->data['jsform']) { - $message = 'Your ' . $this->name . '_submit function should use $form->json_reply to send a response'; + $message = 'Your ' . $this->name . '_submit function should use $form->reply to send a response, which should redirect or exit when it is done. Perhaps you want to make your reply callback do this?'; } else { $message = 'Your ' . $this->name . '_submit function should redirect or exit when it is done'; @@ -763,6 +767,20 @@ }/*}}}*/ /** + * Sends a message back to a form + */ + public function reply($returncode, $message) { + if ($this->submitted_by_js()) { + $this->json_reply($returncode, $message); + } + + $function = $this->get_property('replycallback'); + if (function_exists($function)) { + call_user_func_array($function, array($returncode, $message)); + } + } + + /** * Sends a message back to a jsform. * * The message can contain almost any data, although how it is used is up to @@ -1307,6 +1325,10 @@ // button in the form 'successcallback' => '', + // The PHP callback called to handle replying to the form after + // either a success or fail. Optional + 'replycallback' => '', + // The PHP callback called if there is any validation error. Optional 'errorcallback' => '', This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |