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