summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Wittens <steven@10.no-reply.drupal.org>2006-04-15 21:52:44 +0000
committerSteven Wittens <steven@10.no-reply.drupal.org>2006-04-15 21:52:44 +0000
commitfb8ef283759abcd270bc727fd4af65ddc0fe5b84 (patch)
tree8a64647660167d931cb6a7462de4637378dfb8a1
parent8b04c7f0db4a7a483049635f961d1dcba7e568f1 (diff)
downloadbrdo-fb8ef283759abcd270bc727fd4af65ddc0fe5b84.tar.gz
brdo-fb8ef283759abcd270bc727fd4af65ddc0fe5b84.tar.bz2
#56921: Remove all reference magic from form api. w00t.
-rw-r--r--includes/form.inc50
-rw-r--r--modules/node.module5
-rw-r--r--modules/node/node.module5
-rw-r--r--modules/search.module2
-rw-r--r--modules/search/search.module2
5 files changed, 51 insertions, 13 deletions
diff --git a/includes/form.inc b/includes/form.inc
index 052d9ea46..27120901d 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -333,12 +333,9 @@ function form_builder($form_id, $form) {
$posted = (isset($_POST['edit']) && ($_POST['edit']['form_id'] == $form_id));
$edit = $posted ? $_POST['edit'] : array();
- $ref =& $form_values;
foreach ($form['#parents'] as $parent) {
$edit = isset($edit[$parent]) ? $edit[$parent] : NULL;
- $ref =& $ref[$parent];
}
- $form['#ref'] = &$ref;
if (!isset($form['#value']) && !array_key_exists('#value', $form)) {
if ($posted) {
switch ($form['#type']) {
@@ -402,7 +399,7 @@ function form_builder($form_id, $form) {
// We call this after #process gets called so that #process has a
// chance to update #value if desired.
if (isset($form['#input']) && $form['#input']) {
- $ref = $form['#value'];
+ form_set_value($form, $form['#value']);
}
// Recurse through all child elements.
@@ -437,6 +434,45 @@ function form_builder($form_id, $form) {
}
/**
+ * Use this function to make changes to form values in the form validate
+ * phase, so they will be available in the submit phase in $form_values.
+ *
+ * Specifically, if $form['#parents'] is array('foo', 'bar')
+ * and $value is 'baz' then this function will make
+ * $form_values['foo']['bar'] to be 'baz'.
+ *
+ * @param $form
+ * The form item. Keys used: #parents, #value
+ * @param $value
+ * The value for the form item.
+ */
+function form_set_value($form, $value) {
+ global $form_values;
+ _form_set_value($form_values, $form, $form['#parents'], $value);
+}
+
+/**
+ * Helper function for form_set_value().
+ *
+ * We iterate of $parents and create nested arrays for them
+ * in $form_values if needed. Then we insert the value in
+ * the right array.
+ */
+function _form_set_value(&$form_values, $form, $parents, $value) {
+ $parent = array_shift($parents);
+ if (empty($parents)) {
+ $form_values[$parent] = $value;
+ }
+ else {
+ if (!isset($form_values[$parent])) {
+ $form_values[$parent] = array();
+ }
+ _form_set_value($form_values[$parent], $form, $parents, $value);
+ }
+ return $form;
+}
+
+/**
* Renders a HTML form given a form tree. Recursively iterates over each of
* the form elements, generating HTML code. This function is usually
* called from within a theme. To render a form from within a module, use
@@ -681,14 +717,14 @@ function password_confirm_validate($form) {
if (isset($form['pass1']['#value'])) {
$pass1 = trim($form['pass1']['#value']);
$pass2 = trim($form['pass2']['#value']);
- $form['pass1']['#ref'] = NULL;
- $form['pass2']['#ref'] = NULL;
+ form_set_value($form['pass1'], NULL);
+ form_set_value($form['pass2'], NULL);
+ form_set_value($form, $pass1);
if ($pass1 != $pass2) {
form_error($form, t('The specified passwords do not match.'));
form_error($form['pass1']);
form_error($form['pass2']);
}
- $form['#ref'] = $pass1;
}
elseif ($form['#required'] && !empty($_POST['edit'])) {
form_set_error('pass1', t('Password field is required.'));
diff --git a/modules/node.module b/modules/node.module
index be974062b..cf8c085a2 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -2170,7 +2170,7 @@ function node_form_alter($form_id, &$form) {
*/
function node_search_validate($form_id, $form_values, $form) {
// Initialise using any existing basic search keywords.
- $keys = $form['basic']['inline']['processed_keys']['#ref'];
+ $keys = $form_values['processed_keys'];
// Insert extra restrictions into the search keywords string.
if (isset($form_values['type']) && is_array($form_values['type'])) {
@@ -2180,6 +2180,7 @@ function node_search_validate($form_id, $form_values, $form) {
$keys = search_query_insert($keys, 'type', implode(',', array_keys($form_values['type'])));
}
}
+
if (isset($form_values['category']) && is_array($form_values['category'])) {
$keys = search_query_insert($keys, 'category', implode(',', $form_values['category']));
}
@@ -2197,7 +2198,7 @@ function node_search_validate($form_id, $form_values, $form) {
$keys .= ' "'. str_replace('"', ' ', $form_values['phrase']) .'"';
}
if (!empty($keys)) {
- $form['basic']['inline']['processed_keys']['#ref'] = trim($keys);
+ form_set_value($form['basic']['inline']['processed_keys'], trim($keys));
}
}
diff --git a/modules/node/node.module b/modules/node/node.module
index be974062b..cf8c085a2 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -2170,7 +2170,7 @@ function node_form_alter($form_id, &$form) {
*/
function node_search_validate($form_id, $form_values, $form) {
// Initialise using any existing basic search keywords.
- $keys = $form['basic']['inline']['processed_keys']['#ref'];
+ $keys = $form_values['processed_keys'];
// Insert extra restrictions into the search keywords string.
if (isset($form_values['type']) && is_array($form_values['type'])) {
@@ -2180,6 +2180,7 @@ function node_search_validate($form_id, $form_values, $form) {
$keys = search_query_insert($keys, 'type', implode(',', array_keys($form_values['type'])));
}
}
+
if (isset($form_values['category']) && is_array($form_values['category'])) {
$keys = search_query_insert($keys, 'category', implode(',', $form_values['category']));
}
@@ -2197,7 +2198,7 @@ function node_search_validate($form_id, $form_values, $form) {
$keys .= ' "'. str_replace('"', ' ', $form_values['phrase']) .'"';
}
if (!empty($keys)) {
- $form['basic']['inline']['processed_keys']['#ref'] = trim($keys);
+ form_set_value($form['basic']['inline']['processed_keys'], trim($keys));
}
}
diff --git a/modules/search.module b/modules/search.module
index 4cc487e41..cf4cbc4e9 100644
--- a/modules/search.module
+++ b/modules/search.module
@@ -1006,7 +1006,7 @@ function search_form($action = '', $keys = '', $type = NULL, $prompt = NULL) {
* search form.
*/
function search_form_validate($form_id, $form_values, $form) {
- $form['basic']['inline']['processed_keys']['#ref'] = trim($form_values['keys']);
+ form_set_value($form['basic']['inline']['processed_keys'], trim($form_values['keys']));
}
/**
diff --git a/modules/search/search.module b/modules/search/search.module
index 4cc487e41..cf4cbc4e9 100644
--- a/modules/search/search.module
+++ b/modules/search/search.module
@@ -1006,7 +1006,7 @@ function search_form($action = '', $keys = '', $type = NULL, $prompt = NULL) {
* search form.
*/
function search_form_validate($form_id, $form_values, $form) {
- $form['basic']['inline']['processed_keys']['#ref'] = trim($form_values['keys']);
+ form_set_value($form['basic']['inline']['processed_keys'], trim($form_values['keys']));
}
/**