homepage Welcome to WebmasterWorld Guest from 54.161.185.244
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

    

Bleigle

10+ Year Member



 
Msg#: 10471 posted 4:41 am on Jun 24, 2005 (gmt 0)

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

 

Purple Martin

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 10471 posted 6:11 am on Jun 24, 2005 (gmt 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!

SuperNovaCain

5+ Year Member



 
Msg#: 10471 posted 7:08 am on Jun 24, 2005 (gmt 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

SuperNovaCain

5+ Year Member



 
Msg#: 10471 posted 7:20 am on Jun 24, 2005 (gmt 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

rocknbil

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



 
Msg#: 10471 posted 4:31 pm on Jun 24, 2005 (gmt 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

10+ Year Member



 
Msg#: 10471 posted 2:18 pm on Jul 7, 2005 (gmt 0)

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!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved