Bug #17296
closedpiVars does not support arrays
0%
Description
I just learned the hard way that piVars does not support arrays.
Create a frontend plugin with a <select multiple> field, add some options and select some of them. Then submit the form.
<form>
<select name="tx_foobar][select][]" size="5" multiple>
<option value="1">option 1</option><option value="2">option 2</option><option value="3" selected>option 3</option>
</select>
<input name="save" type="submit" value="save">
</form>
Expected result:
piVars['select'] is an array which contains the selected items
Actual result:
piVars['select'] contains the string "array" :-(
Unfortunately there is no other way to handle <select multiple> than using an array AFAIK.
(issue imported from #M5604)
Updated by Ingo Renner over 17 years ago
please provide more detailed information or I'm going to close your report otherwise
Updated by Franz Holzinger over 17 years ago
You can only enter normal parameters for an extension.
E.g.
http://mytypo3domain.com/index.php?id=32&tx_ttextensionname_pi1[param1]=1&tx_ttextensionname_pi1[param2]=2&tx_ttextensionname_pi1[param3]=3
So you have to repeat the rather long extension array for each extension parameter.
It would be shorter to have:
http://mytypo3domain.com/index.php?id=32&tx_ttextensionname_pi1='param1=1¶m2=2¶m3=3';
This is a proposal in pseudo URL, it must be encoded of course and could be done in better ways. However it would make the URL line smaller and easier to read.
The job to put this into piVars should be done by the tslib_pibase classe.
The relevant code is here:
tslib_pibase:function tslib_pibase() {
// Setting piVars:
if ($this->prefixId) {
$this->piVars = t3lib_div::GParrayMerged($this->prefixId);
----------------
/**
- Returns the GET/POST global arrays merged with POST taking precedence.
- Usage: 1 *
- @param string Key (variable name) from GET or POST vars
- @return array Returns the GET vars merged recursively onto the POST vars.
- @ignore
- @deprecated
*/
function GParrayMerged($var) {
$postA = is_array($_POST[$var]) ? $_POST[$var] : array();
$getA = is_array($_GET[$var]) ? $_GET[$var] : array();
$mergedA = t3lib_div::array_merge_recursive_overrule($getA,$postA);
t3lib_div::stripSlashesOnArray($mergedA);
return $mergedA;
}
Updated by Christian Boltz over 17 years ago
Argh
After creating a small demo extension I couldn't reproduce the problem. I then noticed that the extension where I found the problem mangled piVars via
if ($this->piVars) {
foreach ($this->piVars as $key => $value)
$this->piVars[$key] = htmlspecialchars(stripslashes($value));
}
and stripslashes destroys the array and "converts" it to the string "Array" :-( (which is documented in the PHP documentation, so it isn't a PHP bug)
Sorry that I didn't notice this mangling earlier. Please close this bug as invalid.
(and: Franz, if you want a better URL parameter scheme, please open a new feature request for it.)
Updated by Oliver Hader over 17 years ago
As requested by the reporter, this issue is closed.