/    Sign up×
Community /Pin to ProfileBookmark

submitting the date through a form

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>

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@MstrBobNov 15.2004 — I don't know what your form looks like, but if you want the field to have the default value of the current date, you can do something like this:

[code=php]
<input type="text" name="date" value="<?PHP echo(date("F j, Y")); ?>">
[/code]


Obviously the form would have to be a PHP file to work. That is, if I understand you correctly.
Copy linkTweet thisAlerts:
@bolauthorNov 15.2004 — the form is an HTML file... I think that's the trouble
Copy linkTweet thisAlerts:
@ScleppelNov 15.2004 — if you can have a .shtml page you could maybe use:

[CODE]
<!--#echo var="DATE_LOCAL" -->

<!--#echo var="DATE_GMT" -->
[/CODE]


[URL=http://www.ssi-developer.net/ssi/ssi-date.shtml]more info[/URL]
Copy linkTweet thisAlerts:
@yunaNov 16.2004 — If you're ultimately going to download the contents to Excel, I strongly suggest you look at Excel's native time formats which, like Unix, represent time as a number, then use functions to format the date as necessary.

The problem is that Excel's date format represents time as floating-point number measuring the elapsed time in days since 1/1/1900; in this scheme 1/1/1900 12:00 noon would equal 0.5. PHP uses the "Unix epoch," measuring time in elapsed seconds since midnight on 1/1/1970.

A quick attempt at a function to map Unix datestamps to Excel datestamps might look like this:

[code=php]
function date2xl ($unixdate) {

# first determine date at last midnight
$midnight=mktime(0,0,0,intval(date("m"),$unixdate)),
intval(date("d",$unixdate)),intval(date("Y",$unixdate)));

# calculate elapsed days from 1/1/70 up to midnight
$xldays=floor($midnight/86400);

# determine the remaining fraction of a day
$xldayfrac=($unixdate-$midnight)/86400;

# calculate Excel time by adding the elapsed time in
# days between 1/1/70 and last midnight,
# the number of days between 1/1/1900 and 1/1/1970,
# including 17 (?) leap years, and the elapsed fraction
# of the day since midnight
$xltime=(float) $unixdays + 25567 + $xldayfrac;

# return the xl value
return $xltime;

}
[/code]


I'm not 100% sure about these values; I just did some quick calculations. YMMV
×

Success!

Help @bol spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...