Welcome to WebmasterWorld Guest from 54.145.65.62

Forum Moderators: incrediBILL

Message Too Old, No Replies

     

Bleigle

4:41 am on Jun 24, 2005 (gmt 0)

Inactive Member
Account Expired

 
 


I am trying to use formmail, and need to have the current date output into the email that is sent to me.

I want it to be a hidden field.

Can you help?

Thanks so much

6:11 am on June 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 21, 2002
posts:977
votes: 0


You have at least two options:

1. Use JavaScript to populate the hidden field with the user's current system date. Problems include: if the user has JavaScript turned off you won't get anything, if the user's system is set to the wrong date you'll get the wrong date.

2. Just look at the date the email was sent!

7:08 am on June 24, 2005 (gmt 0)

New User

10+ Year Member

joined:June 12, 2005
posts:20
votes: 0


It sounds like you have a page that gets processed before sending the email.

So another option is script it in during the submission process...
Javascript (on the client side)
or ASP, PHP, JSP, whatever (on the server side)

What kind of host are you on and what technologies are supported?

SuperNĪvaCain

7:20 am on June 24, 2005 (gmt 0)

New User

10+ Year Member

joined:June 12, 2005
posts:20
votes: 0


Sorry for the double post... it's late and I need to read more closely...

I'm not familiar with formmail. It looks like a remotely hosted service, or a prepackaged mailer that you can just "plug'n'play" onto a website (black box).

My best guess is
javascript is your best option.
It can put a date/time stamp into your hidden form field, right at the moment the "submit" button is clicked. At risk of a client not having javascript enabled, the worst that can happen is you get no date/time stamp.

Using ASP, PHP, etc... you can fill the hidden field when the page is created, but if the page is kept open for a couple of hours before the "submit" button is clicked, then, well... your time stamp will be off by that amount too.

Getting more creative, you could have your page submit to an intermediate page, that would in turn, add it's own information and then submit onto your formmail...

SuperNĪvaCain

4:31 pm on June 24, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


Formmail is one of those (insecure!) scripts that accepts whatever variables you sent it. You can also populate a hidden field using Javascript. Keeping that in mind, here's the relevant code outline that will work:

<html><head><title>Get submitted date</title></head>
<body>

<form method="post" onSubmit="return false;">
<input type="hidden" name="submitted_date" value="">
<!-- rest of your form -->
<input type="submit" onClick="addDate(this.form);" value="Submit">
</form>

<script type="text/javascript">
function addDate(form) {
var day = new Date();
// following all on one line
//Months is zero-based (Jan=0, Feb=1.etc.) So must be incremented
var submitted = (day.getMonth()+1)+'/'+day.getDay()+'/'+day.getYear()+' '+day.getHours()+':'+day.getMinutes()+':'+day.getSeconds();
// End all on one line
form.submitted_date.value=submitted;
//uncomment the below to get an alert showing you it indeed works
//alert(form.submitted_date.value);
form.submit();
}
</script>

</body>
</html>

Look for "submitted_date" in your server-side output. If Javascript is disabled, you won't get a submitted date but the form will still work; that's what the onSubmit=return false does.

mkowalski

2:18 pm on July 7, 2005 (gmt 0)

Inactive Member
Account Expired

 
 


This helped me out big time! I was wondering.. I'm using a form that only needs the time in 24hr time but this code appears to output times like 10:7 instead of 10:07. Is there a way to easily format that to read 10:07? Also, if the local computer is set to 24hr clock will it output 24hr times? I modified a couple lines of the code:
<html><head><title>Get submitted date</title></head>
<body>

<form method="post" onSubmit="return false;">
<input type="text" name="submitted_date" value="">
<!-- rest of your form -->
<input type="submit" onClick="addDate(this.form);" value="Submit">
</form>

<script type="text/javascript">
function addDate(form) {
var day = new Date();
// following all on one line
//Months is zero-based (Jan=0, Feb=1.etc.) So must be incremented
var submitted = (+day.getHours()+':'+day.getMinutes());
// End all on one line
form.submitted_date.value=submitted;
//uncomment the below to get an alert showing you it indeed works
//alert(form.submitted_date.value);
//form.submit();
}
</script>

</body>
</html>

THANKS!