Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

HTML Forum


You are currently viewing our HTML Forum as a guest. Please register to participate.
Login



Post a Project »

Find a Professional HTML Freelancer!

Find a Freelancer to help you with your HTML projects

FREE Outsourcing eBook!

Reply
Insert datetime in FORM
Old 07-12-2007, 06:40 AM Insert datetime in FORM
Novice Talker

Posts: 7
Name: Richard Jay
Trades: 0
I need to insert the current date & time as a variable into a Form which is being sent to a credit card payment processor using the POST method. The page is in HTML but PHP or Javascript is possible if required.

1) I want to use the current date & time (including seconds):
<input type="hidden" name="trans_id" value="YYYYMMDDHHMMSS">

2) I want to use the current date:
<input type=”hidden” name=”repeat” value=”YYYYMMDD/monthly/12:50”>

I'm guessing this is quite simple but not too sure how to do it
richardjay is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-12-2007, 09:41 AM Re: Insert datetime in FORM
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Relatively simple at least,

HTML Code:
<script type="text/javascript">
function dateString(which) {
var retVal = "";
var date = new Date();

var Y = date.getFullYear().toString();
var M = (date.getMonth()+1).toString();
	if (M.length == 1) {
		M = "0" + M;
	}
var D = date.getDate().toString();
	if (d.length == 1) {
		d = "0" + d;
	}
var h = date.getHours().toString();
	if (h.length == 1) {
		h = "0" + h;
	}
var m = date.getMinutes().toString();
var s = date.getSeconds().toString();

if (which == "ID") {
	retVal =  Y+M+D+h+m+s ;
}
if (which == "Rep") {
	retVal =  Y+M+D+"/monthly/"+h+ ":" +m ;
}

return retVal;
}
</script>
HTML Code:
<form name="formname" >
<input type="text" name="trans_id" value="YYYYMMDDHHMMSS">
<input type="text" name="repeat" value="YYYYMMDDHHMMSS">
</form>

<script type="text/javascript">
document.forms["formname"].trans_id.value = dateString("ID");
document.forms["formname"].repeat.value = dateString("Rep");
</script>
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-12-2007, 10:41 AM Re: Insert datetime in FORM
Mattmaul1992's Avatar
Ultra Talker

Posts: 486
Name: Matt
Trades: -1
You really don't want to use JavaScript for this. Why? JavaScript is unsecure because it is client-side scripting and it can be turned off or manipulated and not work in older browsers.
So if JavaScript was turned off or the browser was too old to support it you would get no value and a bunch of messed up JavaScript on the page (unless you use HTML <!-- right after the JavaScript declaration).
Plus the time JavaScript returns is the users system clock time. So in other words I could change my system clocks date and time to July 90th 9190 at 40:20 PM. Not good at all. Someone could attack your script and you wouldn't know it was them because the date wouldn't show as the time when you got attacked so it would be a hard thing to prove.
Now you need to control the data. Your server will control it not the users by using PHP.
Here's a script that can do this -
PHP Code:
<?php
$date_time 
date('YmdHis');
$date date('Ymd\/M\/h\:s');
print 
"<input type=\"hidden\" name=\"trans_id\" value=\"$date_time\">
<input type=\"hidden\" name=\"repeat\" value=\"
$date\">";
?>
An example HTML output of this PHP script would be something alone the lines of -
Code:
<input type="hidden" name="trans_id" value="20070712083833">
<input type="hidden" name="repeat" value="20070712/Jul/8:39">
You can format it however you like by editing the PHP variables '$date_time' and '$date' and replacing them with the values in this page - http://us.php.net/manual/en/function.date.php. If you need it reformatted and can't figure it out let me know and I'll do it for you.
That should do it. Hope this helps.
__________________
PHP Code:
$talkupation++; 

Please login or register to view this content. Registration is FREE
- Free IPB forum hosting (releasing today!!!), no ads, free modifications

Last edited by Mattmaul1992; 07-12-2007 at 10:43 AM..
Mattmaul1992 is offline
Reply With Quote
View Public Profile
 
Old 07-12-2007, 10:51 AM Re: Insert datetime in FORM
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
You really don't want to use JavaScript for this. Why? JavaScript is unsecure because it is client-side scripting and it can be turned off or manipulated and not work in older browsers.
You are only half right here.
The rule is to always consider datas comming from a client (browser) to be erroneous, and you must validate them to be sure they are valid, after all... Not the contrario.
Never, ever consider datas sent to your site as being the real one. Even if you compose them yourself in a page. Anything can be forged and faked.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 07-12-2007 at 10:52 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-12-2007, 10:57 AM Re: Insert datetime in FORM
Mattmaul1992's Avatar
Ultra Talker

Posts: 486
Name: Matt
Trades: -1
Such validation might become a problem. You'd still have to use server side scripting to make sure it's not below this date and note above the other or manually change it every day. Otherwise just like I said someone could enter a completely false date. Plus if you have it so that the client specifices time via their system clock everyones time will be different.
Say two people submit the same form at the same time. One from France one from the US. The France date will be different from the US date because of the time-zone difference. It could even be off be an entire day! So the time and maybe even day would be of no use even with advanced validation using JavaScript.
This is all speaking for this case only. Besides that I agree completely with what you're saying.
__________________
PHP Code:
$talkupation++; 

Please login or register to view this content. Registration is FREE
- Free IPB forum hosting (releasing today!!!), no ads, free modifications
Mattmaul1992 is offline
Reply With Quote
View Public Profile
 
Old 07-12-2007, 12:00 PM Re: Insert datetime in FORM
Novice Talker

Posts: 7
Name: Richard Jay
Trades: 0
All good stuff, thanks guys.

MATT - I'm a bit confused by the backward and forward slashes in the PHP code ... are they all supposed to be there or did the forum add them by mistake after you'd pasted the code in ?
richardjay is offline
Reply With Quote
View Public Profile
 
Old 07-12-2007, 12:17 PM Re: Insert datetime in FORM
Ninja's Avatar
Experienced Talker

Posts: 30
Trades: 0
The \(slash) escapes the "(quote) so that it will appear in the html
PHP Code:
print"/"" 
Outputs
Code:
"
I use echo intead of print, but basically I think they are the same
Ninja is offline
Reply With Quote
View Public Profile
 
Old 07-12-2007, 12:48 PM Re: Insert datetime in FORM
Novice Talker

Posts: 7
Name: Richard Jay
Trades: 0
Ok, thanks. But there is something else I don't understand.

I don't want to output the results to HTML. As I stated in my initial email this is to be parsed via POST to a payment processor, so my code currently looks like this:

<form action="https://www.secpay.com/java-bin/ValCard" method="post">
<input type="image" src="x-click-but20.gif" border="0" name="submit">
<img alt="" border="0" src="pixel.gif" width="1" height="1">
<input type="hidden" name="trans_id" value="">
<input type="hidden" name="merchant" value="">
<input type=”hidden” name="repeat" value="">
<input type="hidden" name="currency" value="GBP">
</form>

So how do I insert the output from the PHP script into the "trans_id" and "repeat" values ?
richardjay is offline
Reply With Quote
View Public Profile
 
Old 07-12-2007, 01:06 PM Re: Insert datetime in FORM
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
HTML Code:
<form action="https://www.secpay.com/java-bin/ValCard" method="post">
<input type="image" src="x-click-but20.gif" border="0" name="submit">
<img alt="" border="0" src="pixel.gif" width="1" height="1">
<input type="hidden" name="trans_id" value="<?php echo $transId;?>">
<input type="hidden" name="merchant" value="">
<input type=”hidden” name="repeat" value="<?php echo $repeat;?>">
<input type="hidden" name="currency" value="GBP">
</form>
Replace $repeat and $transId with your variables, simply.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-19-2007, 01:17 PM Re: Insert datetime in FORM
Novice Talker

Posts: 7
Name: Richard Jay
Trades: 0
Thanks for all your help guys. Unfortunately it just got a little more complicated in that I need to increase the month by one.

So, today it should read 20070819 and for example on 19th December 2007 it should read 20080119. Any ideas ?

Currently using this :-

<?php
$date_time = date('YmdHis');
$date = date('Ymd');
?>
richardjay is offline
Reply With Quote
View Public Profile
 
Old 07-19-2007, 02:16 PM Re: Insert datetime in FORM
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
PHP Code:
//For reference:
//int mktime ( [int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst]]]]]]] )
$timestamp=mktime(date('H'), date('i'), date('s'), date('m')+1date('d'), date('Y'));
$dateTime=date('YmdHis'$timestamp); 
To summarize it, date() work against the current time represented by a timestamp.
But you can transform any given time by forging the correcponding timestamp, and passing that time to date().
It's what mktime() do. Simply decompose the components of the date you want, and do a +1 on the part you need. If this increment make a change in the month or year, mktime() will handle it.

http://www.php.net/manual/en/function.mktime.php
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-19-2007, 02:36 PM Re: Insert datetime in FORM
Novice Talker

Posts: 7
Name: Richard Jay
Trades: 0
That all makes sense, thanks. I'll try it and let you know if I get stuck.
richardjay is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Insert datetime in FORM
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35182 seconds with 12 queries