I have a web form and a processor.php file that outputs the form data to a text file. The output currently puts all new info on one line per form field with a line break so for two form submissions, the output looks like this:
ITEMS SELECTED: one
two
three
INFORMATION:
First Name: John
Last Name: Smith
ITEMS SELECTED:
one
three
INFORMATION:
First Name: Bob
Last Name: Jones
I would like it to output the text into a tab-delimited format that will make it easy to import into excel so that the form field labels are appended to the top row and every form field submission gets plugged into its corresponding column.
Ideally, it would look like this:
ONE TWO THREE First Name Last Name
X X X John Smith
X X Bob Jones
Does anyone know how to re-format this to generate this type of output?
Here's my code:
// Checkbox handling
$field_1_opts = $POST['field_1'][0]."
". $POST['field_1'][1]."
". $_POST['field_1'][2];
$fileLine = "ITEMS SELECTED: $field_1_opts
INFORMATION: " . $POST[' '] . "
First Name: " . $POST['field_2'] . "
Last Name: " . $POST['field_3'] . "
Title: " . $POST['field_4'] . "
Organization: " . $POST['field_5'] . "
Investor Type: " . $POST['field_6'] . "
Address 1: " . $POST['field_7'] . "
Address 2: " . $POST['field_8'] . "
City: " . $POST['field_9'] . "
State/Province: " . $POST['field_10'] . "
Zip Code/Zone: " . $POST['field_11'] . "
Phone: " . $POST['field_12'] . "
E-mail: " . $POST['field_13'] . "
Questions/Comments: " . $POST['field_14'] . "
Country: " . $_POST['field_15'] . "
Date and Time: " . $dtstamp . "
";
$filename = 'kitrequest.txt';
if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a'))
{
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($handle, $fileLine) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
fclose($handle);
} else {
echo "The file is not writable";
}
include("confirm.html");
?>