I am using a php script “apgform” suggested to me by a member recently.
It takes information submitted in a form and displays it in an excel spread sheet. I have finally got it working but I have a problem.
I would like the first field to display the date when the form was submitted.
I tried using JS to create a date object and make it the default value of a form entry, but it seems the value attribute won’t accept variables.
how could I modify the following php code to make the first headding entry read “date” and imput the submission date underneath, each time an entry is made.
The whole script follows
<html>
<head><title>
<?php
//code by apg88 “apgForm(toExcel) 1.1”
if(!$title){
$title = “apgForm”;
}
echo $title .'</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>
<body>’;
if(!$filename){
$filename = “form.xls”;
} else {
if(!(stristr($filename,”.xls”))){
$filename = $filename . “.xls”;
}
}
$continue = ‘ Here is a the Comment form your info was just sent to <a href=”test.xls”>Click
Here</a> to see the excel file.<br> <a href = “index.php”>Click Here</a> To Return to apgForm ‘;
$lbChar = ” “;
$tab = “t”; //chr(9);
$cr = “n”; //chr(13);
if($_GET){
$array = $_GET;
}else if($_POST){
$array = $_POST;
} else {
echo “You must Access this file through a form.”;
}
if($array){
$keys = array_keys($array);
foreach($keys as $key){
if(strtolower($key) != ‘filename’){
$header .= $key . $tab;
}
}
$header .= $cr;
foreach($keys as $key){
if(strtolower($key) != ‘filename’ && strtolower($key) != ‘title’){
$array[$key] = str_replace(“n”,$lbChar,$array[$key]);
$array[$key] = preg_replace(‘/([rn])/e’,”ord(‘$1’)==10?”:””,$array[$key]);
$array[$key] = str_replace(“\”,””,$array[$key]);
$data .= $array[$key] . $tab ;
}
}
$data .= $cr;
if (file_exists($filename)) {
$final_data = $data;
} else {
$final_data = $header . $data;
}
// open the file and write to it
$fp = fopen($filename,”a”);
if($fp){
fwrite($fp,$final_data);
fclose($fp);
echo “Form Received Successfully! <br> ” . $continue;
} else {
echo “Error receiving form! <br>” . $continue;
}
}
//Copyright ?2004 apg88. All Rights Reserved
?>
</body>
</html>