Forum Moderators: mack

Message Too Old, No Replies

need method to count form clicks

         

cham1

10:41 pm on May 26, 2004 (gmt 0)

10+ Year Member



I have a script in perl that contains an input form.
I am trying to find a way to count the number of times the submit button is pressed.

Any ideas on how to get that count?

I was thinking a hidden page counter might be close, but it wont count actual button presses and it would have to count each hit the page is reloaded for the forms script. If this is the way to go, any good counters that can provide daily logging?

Thanks.

Birdman

11:40 pm on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It can be done very easily but the catch is, you have to know some Perl. You could edit some lines right into the script that processes the form and have it write to a database or a text file.

Wait! The more I think of it, you should be able to use your log records(stats) to check the hits on the file that processes the form. Look at the source code of the form page and in the <form> tag you'll see the action="" attribute. That'll be the file to look for in your stats.

cham1

11:52 pm on May 26, 2004 (gmt 0)

10+ Year Member



the action="" is blank. The script runs on the same page and refreshes the page with the output.

I thought of using the action= to somehow do this but I don't know enough to figure it out without a little help.

Thanks

Birdman

12:50 am on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, here's one for you. It's Javascript. Put this in the <head> of the page that contains the form.

<script type="text/javascript">
function logClick(){
URL = "/example.gif";
webBug = new Image();
webBug.src = URL;
return true;
}
</script>

Then in the <form> tag add this:

onsubmit="return logClick();"

So it will look something like:

<form action="" method="post" onsubmit="return logClick();">

cham1

1:07 am on May 27, 2004 (gmt 0)

10+ Year Member



Ok, I understand that except how I get the count.

Is it by seeing how many times the URL "example.gif" is accessed?

thanks.

Birdman

10:29 am on May 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, that's the easiest way. Otherwise you have to write a cgi script to log the hits.