Forum Moderators: coopster
<?php
// Collect all the form data into an easier variable.
$form_data = ($_POST);
$timestamp = date('Y-m-d-H-i-s');
$mount_point = "c:/test";
$survey_filename = $mount_point ."/" .$form_data[':SURVEY:'] ."-" .$timestamp .".txt";
if (($survey_fp = fopen($survey_filename, "wb")) === FALSE)
{
//Could not write to flash trying internal disk
$survey_filename = "c:/test" .$form_data[':SURVEY:'] ."-" .$timestamp .".txt";
if (($survey_fp = fopen($survey_filename, "wb")) === FALSE)
{
die('FATAL ERROR: Could not save survey');
}
}
// Write form data
foreach ($form_data as $name=>$value)
{
fwrite($survey_fp, "$name=$value\r\n");
}
// close the survey text file
fclose ($survey_fp);
?>
V15=8
V154=7
V155=1
V16=t
V15=1;3;8
V154=2;4;7
V155=1
V16=t
But I want to get multiple response questions to show up and they should look like this:
foreach ($form_data as $name=>$value){
fwrite($survey_fp, "$name=");
if ($name=='my_multiple_select') {
$selected_count = count($value)-1;
for ($i=0;$i<=$selected_count;$i++) {
fwrite($survey_fp,$value[$selected_count]);
if ($i<$selected_count) {
fwrite($survey_fp,':');
}
}
fwrite($survey_fp,"\r\n");
}
else { $fwrite($survey_fp,$value\r\n"); }
}
//
// close the survey text file
fclose ($survey_fp);
...but would only output the last response from multiple response questions
<select name="myselect[]" id="myselect" multiple="multiple" size="10">
<?php
header("Content-type:text/html");
if (isset ($_POST['mytest']) and ! empty($_POST['mytest'])) {
foreach ($_POST['mytest'] as $value) {
echo "<p>$value selected</p>\n";
}
}
else {
echo '
<form action="test-multiple.php" method="post">
<p>Select multiple items with CTRL or shift.</p>
<p><select multiple="multiple" name="mytest[]" id="mytest" size="12">
<option value="">Select from below</option>
<option value="red">red</option>
<option value="green">green</option>
<option value="blue">blue</option>
<option value="yellow">yellow</option>
<option value="orange">orange</option>
<option value="violet">violet</option>
<option value="gold">gold</option>
<option value="silver">silver</option>
<option value="Always Sunny">Always Sunny</option>
</select></p>
<p><input type="submit" value="test it"></p>
';
}
?>