Solved

how to POST the form button click time to PHP?

Posted on 2012-03-13
13
429 Views
Last Modified: 2012-03-25
For the following button action,  I cannot able to post the "new Date();" to PHP and into the DB...  Bascially i am trying to send the button click time-stamp to Database. How do I POST the button click time to PHP?


 <?php
$baction = pg_escape_string($_POST['baction']);


$sql = "INSERT INTO table VALUES('$baction');";

 ?>

<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >

<input type="baction" value="Action" name="baction" onclick="init(); new Date();">

</FORM>
0
Comment
Question by:Mike
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 4

Expert Comment

by:Paul-B
ID: 37718393
Is there a long time between the clicking of the button and the processing to the DB or something? I mean couldn't you just call the date("ymd") at the time of the actual INSERT?
0
 
LVL 11

Assisted Solution

by:maeltar
maeltar earned 50 total points
ID: 37718582
Are you wanting to insert the timestamp of when the button was clicked or when the record is inserted ?

if the latter you could use :

$sql = "INSERT INTO table VALUES(NOW())";

but you need to ensure the datatype of the column is datetime
0
 
LVL 7

Assisted Solution

by:Ironhoofs
Ironhoofs earned 50 total points
ID: 37719181
The button itself is not posted. You can declare another input and change the value of this input when the button is clicked. For example:

<FORM name="navForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
   <input type="hidden" name="baction" value="">
   <input type="submit" value="Action" onclick="document.navForm.baction.value=new Date().getTime();">
</FORM>

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Ironhoofs
ID: 37719207
In my example i used "new Date().getTime()" because it returns milliseconds elapsed sinds 1-1-1970, while "new Date()" only returns full seconds. Use what best suits your needs.

Also remember that anything posted is a string and you have to format/convert it to the
correct type before inserting it into the database.
0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 50 total points
ID: 37719521
This article contains information about how to get the client date and time through a form.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html
0
 

Author Comment

by:Mike
ID: 37720204
Yes “Paul-B”, there is a time gap between (baction) button click and final form SUBMIT button click.

Yes, “maeltar” I am able to capture the final submit button time with the following php-postgresql connection code

$sql = "INSERT INTO users VALUES (clock_timestamp());

But here, I also wanted to capture the timestamp when user click “baction” button.



<input type="baction" value="Action" name="baction" onclick="init(); new Date();">

When user click “baction” button, it call the JavaScript function init() and it works great, but also I want to capture the button click time at the same time

Within the javascript file where init() reside, I tried to insert the following

Function currenttime()
{
var bclicktime = new Date()
}

And try to POST to PHP sometime like $btime = pg_escape_string($_POST[‘baction’]);

I could be a small little thing but I am not thinking correctly… Basically I want the “baction” button to execute “init();” function (it is working great) at the same time want to capture the button click timestamp POST to PHP and pass it down to Postgresql.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 37720419
Go to the article posted above and read the paragraphs captioned:
Storing Date and Time in Your Database
PHP and MySQL Have Different Time Zone Settings (Test on your system to see if this is also applicable to PostGreSQL - I would expect that it is applicable)
Practical Application #8
0
 

Author Comment

by:Mike
ID: 37720975
"Ray_Paseur"
I didn't find anyting in the above link but I checked section "Practical Application #8" in your "Handling Date and Time in PHP and MySQL" article.

$client_offset_minutes = $_POST["date_O"];

<form method="post">
<input name="date_O" id="dateTime_O" type="hidden" />
<input type="submit" value="CHECK CLIENT DATETIME" />
</form>

<script type="text/javascript">
var dateObject = new Date();
document.getElementById("dateTime_O").value =dateObject.getTimezoneOffset();
</script>


The above code seems like for page load not for button click.
I didn't try yet, but if I replace type="hidden" with "button" should this POST button click timestamp to "$client_offset_minutes"?

<input type="button' name="date_O" id="dateTime_O" onlick="init();" />
0
 

Author Comment

by:Mike
ID: 37722474
It is not working for me, any help on capturing the button click time (not submit button click time).
0
 
LVL 15

Assisted Solution

by:StingRaY
StingRaY earned 50 total points
ID: 37723216
Like this?

<FORM name="navForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
   <input type="button" name="baction" value=""  onclick="this.value=new Date().getTime();">
</FORM>

Open in new window

0
 

Accepted Solution

by:
Mike earned 0 total points
ID: 37726904
After serveral tries, I am coming to a conclusion that we cannot use second BUTTON within the same FORM that has SUBMIT button to POST data to PHP...
When I change the type="button" to type="radio" the problem is gone. I still like to use the button as it is more user friendly, I guess i am stuck with "radio/checkbox" type.  I might be wrong, if I am wrong please do correct me.


 <?php
$baction = pg_escape_string($_POST['baction']);
$sql = "INSERT INTO table VALUES('$baction');";

echo .$baction.;
 ?>

<FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" >
<input type="radio" value="Action" name="baction" onclick="init();" onmouseup="this.value=new Date();">

<input .....
<input .....
<input .....
<input .....

<input type="submit" name="submit" value="SET">
</FORM>
0
 
LVL 7

Expert Comment

by:Ironhoofs
ID: 37728304
I have completly lost you there. You can have several submit buttons in a form, but what problem does the radio button solve that the submit button didn't?
0
 

Author Closing Comment

by:Mike
ID: 37762390
For my situation, chaning type="button" to type="radio" worked. Unfortunatly i cannot use multiple submit button, just wanted to use regular button.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question