Solved

how to POST the form button click time to PHP?

Posted on 2012-03-13
13
425 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:mkanagar
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 109

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:mkanagar
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 109

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:mkanagar
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:mkanagar
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:
mkanagar 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:mkanagar
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP query / monitor data from Telnet to MySQL 7 52
html input 8 43
Explain this javascript function to me 2 29
send email part1 9 28
This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

830 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