[pmwiki-devel] function InputDefault
Hans
design5 at softflow.co.uk
Tue Jul 15 04:52:50 CDT 2008
Monday, July 14, 2008, 11:45:12 PM, Patrick wrote:
> At the moment I disagree with this a bit as written above --
> shouldn't the control name have a [] or something to indicate that
> it's an array?
Yes, that's what I have been using extensively:
Input control names like var[] or var[1], var[2] etc.
Using names like var[] repeated in several fields
produces input from var[0], var[1], etc in the
$_POST array. I use that in form markup which can be re-used several
times, like (:foxadd ...:).
An upgraded RequestArgs function would help here.
something like this perhaps;
## get arguments from POST or GET
function RequestArgs ($req = NULL) {
if (is_null($req)) $req = array_merge($_GET, $_POST);
foreach ($req as $key=>$val) {
if(is_array($val))
foreach($val as $k=>$v) {
$req[$key][$k] = str_replace("\r",'',stripmagic($v));
}
else $req[$key] = str_replace("\r",'',stripmagic($val));
}
return $req;
}
Using names with explicit index like var[1], var[3]
makes it possible that InputValues can repopulate the fields
with (:input default request=1:), if the InputToHTML() function
is upgraded as well.
> Also, I think we'd need to update the InputToHTML() function
> to be able to handle arrays (since the whole purpose of
> $InputValues is to be able to set things to be used by
> (:input:) controls).
I did some succesful tests with adding this bit of code to the
function:
after line: $name = $opt['name'];
if (preg_match("/(\\w+)(\\[(\\d*)\\])/",$name,$m)) {
if (!isset($opt['value']))
$opt['value'] = $InputValues[$m[1]][$m[3]];
}
The preg pattern is very basic and restrictive and no doubt you know
a better one. I just wanted to filter the var[nnn] names and assign
proper array elements.
Hans
More information about the pmwiki-devel
mailing list