track content of the form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
junjustkim
Forum Commoner
Posts: 44
Joined: Thu May 22, 2008 8:48 pm

track content of the form

Post by junjustkim »

Hi to all

How can I track that if the user attempt to click any button or input value in any field then I will remind them to login first if not yet log.

Thanks in advance

Tirso
irfan798
Forum Newbie
Posts: 11
Joined: Tue Jul 15, 2008 3:45 am
Location: Turkey

Re: track content of the form

Post by irfan798 »

You can use javascript whit php

Code: Select all

onchange="" 
onclick="" 
onfocus=""
use them
For example:

Code: Select all

<input name="" onchange="attempt();"  type="text" />
Javascript
x=1;
<?
And use php for looking if user login like
If (user login) { echo "x=2;";}
?>
if(x=1) {define function attempt() here} else {again define function attempt() here}
Javascript
Look this links:
http://tr2.php.net/manual/en/book.session.php
http://www.w3schools.com/JS/js_functions.asp
junjustkim
Forum Commoner
Posts: 44
Joined: Thu May 22, 2008 8:48 pm

Re: track content of the form

Post by junjustkim »

HI,


thanks for your immediate replied, Bu do i need to put this javascript "onchange,onclick,onfocus" to all my field and button like your example (<input name="" onchange="attempt();" type="text" />). I have a lot of field and button to my forms.

Thanks

Tirso
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

Re: track content of the form

Post by dhrosti »

this is a javascript question really, but anyway...

you can use a for loop to assign event handlers to all your input elements in a few lines...

Code: Select all

function assignHandlers() {
    var inputs = document.getElementsByTagName('input');
    for (var i=0; i<inputs.length; i++) {
        inputs[i].onclick = attempt;
    }
}
window.onload=assignHandlers;
Last edited by dhrosti on Fri Jul 18, 2008 7:59 am, edited 1 time in total.
junjustkim
Forum Commoner
Posts: 44
Joined: Thu May 22, 2008 8:48 pm

Re: track content of the form

Post by junjustkim »

Thank you so much for your time and effort, It was contributed a lot for me. Now I would continued my development for almost 3 days hang up.

Again, thank you so much


Tirso
Post Reply