From f648662d2aa60a2c5442ad0051da4646e920a8d5 Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Tue, 2 Oct 2007 07:28:48 +0000 Subject: [PATCH] allow multi dimensional arrays for PMA_generate_common_hidden_inputs() --- libraries/url_generating.lib.php | 53 +++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/libraries/url_generating.lib.php b/libraries/url_generating.lib.php index 16b7a97ce..ac4c3e738 100644 --- a/libraries/url_generating.lib.php +++ b/libraries/url_generating.lib.php @@ -10,6 +10,7 @@ * Generates text with hidden inputs. * * @see PMA_generate_common_url() + * @uses PMA_getHiddenFields * @param string optional database name * @param string optional table name * @param int indenting level @@ -76,14 +77,56 @@ function PMA_generate_common_hidden_inputs($db = '', $table = '', $indent = 0, $ } } - $spaces = str_repeat(' ', $indent); + return PMA_getHiddenFields($params); +} - $return = ''; - foreach ($params as $key => $val) { - $return .= $spaces . '' . "\n"; +/** + * create hidden form fields from array with name => value + * + * + * $values = array( + * 'aaa' => aaa, + * 'bbb' => array( + * 'bbb_0', + * 'bbb_1', + * ), + * 'ccc' => array( + * 'a' => 'ccc_a', + * 'b' => 'ccc_b', + * ), + * ); + * echo PMA_getHiddenFields($values); + * + * // produces: + * + * + * + * + * + * + * + * @param array $values + * @param string $pre + * @return string form fields of type hidden + */ +function PMA_getHiddenFields($values, $pre = '') +{ + $fields = ''; + + foreach ($values as $name => $value) { + if (! empty($pre)) { + $name = $pre. '[' . $name . ']'; + } + + if (is_array($value)) { + $fields .= PMA_getHiddenFields($value, $name); + } else { + $fields .= '' . "\n"; + } } - return $return; + return $fields; } /**