I am trying to pass an array of checkbox inputs from an html, to initial php which generates a new page layout and then called another php to populate it. The php files are using the serialize and unserialize commands on the array variable argument but it not working correctly.
The initial html form is basically doing this:
<form name="ppFrom" action="pp_GeneratePage.php" method="post">
<h2>Filter out the following TDRSSes or Ground Stations:</h2>
<input id="cfButton" type="button" value="Clear filters" onclick="toggleOff(this);" /><br>
<input type="checkbox" name="Filter[]" value="SGS">SGS
<input type="checkbox" name="Filter[]" value="AGS">AGS
<input type="checkbox" name="Filter[]" value="SKS">SKS
<input type="checkbox" name="Filter[]" value="WPS">WPS
<input type="checkbox" name="Filter[]" value="PF1">PF1<br>
<input type="checkbox" name="Filter[]" value="171">171
<input type="checkbox" name="Filter[]" value="TDW">TDW
<input type="checkbox" name="Filter[]" value="TDE">TDE
<input type="checkbox" name="Filter[]" value="TR3">TR3
<input type="checkbox" name="Filter[]" value="275">275<br>
In the pp_GeneratePage.php I can print out the check items ok (I checked SGS and AGS): print_r($_POST['Filter']); prints output: Array ( [0] => SGS [1] => AGS )
The problem starts when I try and pass the Filter array down to the php file which does the real work. This is the code I see when I do view source command:
<frame name="AquaMB" src="pp_ContactRangesPanel.php?sc=Aqua&path=/var/www/html/java_clocks/Aqua/terra_aos_times&filter=a:2:{i:0;s:3:"SGS";i:1;s:3:"AGS";}#target" scrolling=auto frameborder=0>
As you can see I have 3 arguments being passed to the pp_ContactRangesPanel.php file via the src parameter: sc=Aqua, path=/var/www/html/java_clocks/Aqua/terra_aos_times, and an array Filter which I serialized to filter=a:2:{i:0;s:3:"SGS";i:1;s:3:"AGS";}.
This is the print code:
$filterList = serialize($_POST["Filter"]);
printf ("<frame name=\"%sMB\" src=\"pp_ContactRangesPanel.php?sc=%s&path=%s&filter=%s#target\" scrolling=auto frameborder=0>
", $aMissions[$c], $aMissions[$c], $MissionInputPaths[$aMissions[$c]], $filterList);
In pp_ContactRangesPanel.php I can see the first two arguments fine, but filter array is truncated as follows: I see "a:2:{i:0;s:3:" but I should see "a:2:{i:0;s:3:"SGS";i:1;s:3:"AGS";}"
import_request_variables("gP", "var_");
echo "sc $var_sc <br>";
echo "path $var_path <br>";
$filterList = unserialize($var_filter);
echo "filter $filterList <br>";
output is
sc Aqua
path /var/www/html/java_clocks/Aqua/terra_aos_times
filter
If I do this instead:
$filterList = isset($_GET['filter']) ? $_GET['filter'] : null;
echo "fitler $filterList end<br>";
$afilter = unserialize($filterList);
echo "fitler2 $afilter <br>";
The out is:
fitler a:2:{i:0;s:3: end
fitler2
This is the same as if I did a
echo "path $var_filter <br>";
So somehow the variable is being truncated so I can't unserialize it successfully. I think is the double quotes generated by the serialize command but I don't what the workaround is for it. If I pass the filter without serializing it all I see is ARRAY when I print out a entry it doesn't work.
So what am I doing wrong? If is the double quotes, what is the workaround so it parses ok?
As a workaround I replaced the double quote with underscores to successfully pass the serialized array information down. See example:
$filterListRaw = serialize($_POST["Filter"]); $filterList = str_ireplace('"', '_', $filterListRaw);
In the called html file I then restore the double quotes and then unserialize. $filterListRaw = str_ireplace('_', '"', $var_filter); $filterList = unserialize($filterListRaw);
I still think I am doing this the hard way.