Not getting complete form data to save to text

Hi,

I've been up for a couple of nights trying to get the following code to save the complete form data.

I am using the following code to save from a form survey


<?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);

?>


The problem is that the code would post single response, but would only output the last response from multiple response questions, like this:
V15=8
V154=7
V155=1
V16=t




But I want to get multiple response questions to show up and they should look like this:
V15=1;3;8
V154=2;4;7
V155=1
V16=t




I'm still looking into it, but my experience with php script is limited, so please let me know if you have any hits as to what the problem might be.

Thanks in advance


Multiple selects and other elements can in the form of an array.

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);


Something "like that" should lead the way.
0 Komentar untuk "Not getting complete form data to save to text"

Back To Top