This topic is locked

Checkbox which records completion date

10/7/2008 4:03:09 PM
PHPRunner General questions
K
Khris author

I have a table setup with a Checkbox, and a Date/Time field (among others).
What I'd like to happen is that as soon as the Checkbox is selected and the record saved, the Date/Time field is populated with the current Date/Time so as to keep a record as to when that record was "Completed".
I know I have to set this up as as custom code, but I'm not entirely sure how it needs to be setup or where it should go.
Any help will be appreciated.

T
thesofa 10/7/2008

I have a table setup with a Checkbox, and a Date/Time field (among others).

What I'd like to happen is that as soon as the Checkbox is selected and the record saved, the Date/Time field is populated with the current Date/Time so as to keep a record as to when that record was "Completed".
I know I have to set this up as as custom code, but I'm not entirely sure how it needs to be setup or where it should go.
Any help will be appreciated.



well ther pseudo code is along the lines of

If $values["checkbox"];

$values["date/time"]=now();
K
Khris author 10/7/2008

Since it's a checkbox, and the type is tinyint, the only options are 0 and 1. So how do I tell it that if the Checkbox = 1, then assign the date/time field to "now()"?

T
thesofa 10/8/2008

just try the code, if checkbox is 0 then it will not run,
If $values["checkbox"];

$values["date/time"]=now();
have a look at the Before record added event on the add page

// Parameters:

// $values - Array object.

// Each field on the Add form is represented as a 'Field name'-'Field value' pair
//********** Custom code ************

// put your custom code here
If $values["checkbox"];

$values["date/time"]=now();
return true;
// return true if you like to proceed with adding new record

// return false otherwise


should do what you want

L
laonian 10/8/2008

You may want to try this code:
If ($values["Checkbox"]==1)

$values["Date/Time"]=now();
My two cents.

K
Khris author 10/8/2008

Here's what I had to change it to.

If ($values["completed"]=1)

$values["date"]=now();
K
Khris author 10/8/2008

You may want to try this code:

If ($values["Checkbox"]==1)

$values["Date/Time"]=now();
My two cents.


Thanks, I actually got it figured out and posted pretty much the same thing a minute after you.
Does it make a difference to only use one equals sign instead of two?

L
laonian 10/8/2008

Thanks, I actually got it figured out and posted pretty much the same thing a minute after you.

Does it make a difference to only use one equals sign instead of two?


Yes. it does. Single sign means you assign the value to it. Double means a condition.
My two cents.

T
thesofa 10/8/2008



Yes. it does. Single sign means you assign the value to it. Double means a condition.
My two cents.


If ($values["completed"]);



should work, it just checks for the existence of a value in Completed other than 0, you do not need to use

If ($values["completed"]==1)

L
laonian 10/8/2008


If ($values["completed"]);



should work, it just checks for the existence of a value in Completed other than 0, you do not need to use

If ($values["completed"]==1)


code

If ($values["completed"]) //";" should be removed
may work or may not work. If the "completed" field has been given a default value (e.g., 0) in the database, your code may cause a problem.
code

If ($values["completed"]==1)

seems more secure to me.

K
Khris author 10/8/2008



code

If ($values["completed"]) //";" should be removed
may work or may not work. If the "completed" field has been given a default value (e.g., 0) in the database, your code may cause a problem.
code

If ($values["completed"]==1)

seems more secure to me.


IF ($values['completed"]) did not work for me at all, I had to use IF($values["completed"]==1)