tags:

views:

49

answers:

2

Hi Friends,

I have a text field for documentation, which is working good. Now the problem is whenever user enters some new text into it. I need a date in format(dd.mm.yy), that should be attached to it automatically, with the time stamp.

For example, when the user first enters, "Problem with production". then clicks save then it should display as 19.10.10 16:39 "Problem with production".

After that if someone else changes the field and adds, "In development phase".

it should be 19.10.10 18:39 "Problem with production", 29.10.10 16:59 "In development phase".

While sumbitting the form, i am not able to track the text that is newly added. As i will get the complete text in post variables.

I found a dirty trick, placing some wierd character after saving the text. Now in my post variables, i will be able to differentiate what is the old text and what is newly added. Add current time stamp to the newly added one.

I would be glad if some one can suggest me a better procedure.

Thanks in advance!

A: 

Not sure I quite follow - You could have a hidden field in the form which defaults to the date - it would then be submitted as a seperate post variable...

<form>
<input type='text' name='textfieldforcomments' />
<input type='hidden' name='datetracker' value='".date("d.m.y h.i")."'/>
</form>
Ergo Summary
+1  A: 

Off the top of my head a couple of options:

(a) With JS - change trigger

Some javascript on the text field that triggers sets a value in a hidden form field. This field is posted back to PHP so it knows the text field may have changed (still can't tell if the user changed it then changed it back).

eg. JS trigger on field change.

<input type="text" name="textfield" 
   onChange="this.form["textfieldchanged"].value=1;" />
<input type="hidden" name="textfieldchanged" value="" />

(b) With PHP - change detect

Upon form submit check the current version of the field with the submitted version, if it's changed then store the new version.

eg. PHP compare

if ($_REQUEST["textfield"]!=$current_textfield) {
  //...
}

In both cases, when actually storing the value, now just add a date from PHP.

code: final PHP piece

function storeText($text) {
   $date=Date();
   //Store $text+$date .. file, SQL, not sure what you're doing here.
}

You could also use JS to set a date on a hidden field when the text is updated (rather than a flag). This has the advantage that the local-system date is included with the form-submit (especially helpful if users are in different timezones) but has the disadvantage users could game your software by changing their local clock when they're submitting entries... imagine someone wanted to appear to have added text before someone else, they could just set their clock back - make the submit - set the clock to the correct time and carry on.

Rudu