This topic is locked

Checkbox Date

10/29/2009 5:55:12 PM
PHPRunner General questions
greggk author

Hello,

I have a problem which I thought I knew how to handle, but it's not working out.

I have a table with 2 fileds, receivedCK and receivedDate

The receivedCH is a checkbox, and the receivedDate is obvioulsy the date.

On my edit page, I wanted to automatically fill in the receivedDate field as soon as you click the checkbox.

This is what I have.
if (isset($_POST["receivedCK"])) {

$value["receivedDate"] = now();

}
It is not working like it should, any suggestions?

greggk author 10/29/2009

After reading some more on the forums I have tried two other options, both which failed.
if ($_REQUEST['receivedCK'] == "ON")

{

$values["receivedDate"] = now();

}
and
if ($_POST['receivedCK'] == "ON")

{

$values["receivedDate"] = now();

}

J
Jane 10/30/2009

Hi,
to change field values on the fly use JavaScript code. To add JavaScript switch to HTML mode on the Visual Editor tab and add your code at the end of the page.

Here is just a sample:

<script>

document.forms.editform.value_FieldName.onchange = function()

{

if (document.forms.editform.value_FieldName.checked==true)

{

//add your code here

...

}

}

</script>



More info about javaScript functions and methods here:

http://www.w3schools.com/js/default.asp

http://www.w3schools.com/jsref/jsref_getDate.asp

greggk author 10/30/2009

Thanks, I didn't think of doing it via javascript. That should be possible, I did do some additions before via javascript and they worked fine. However, was there anything wrong with my php code? Why it wouldn't work?

greggk author 10/30/2009

I got it to work.

Here is the change I made.
global $conn;

if ($values["receivedCK"] > 0) {

$values["receivedDate"] = now();

}
I was noticing that checked had a value of 1, while unchecked had a value of 0, so this seems to put the date on it correctly.
Now, my next problem is, there are several check boxes on the page, so the user will have to check multiple boxes and different times. Every time they hit save, it changes the date again. How can I prevent the date to change, if is already there? Probably something like another IF fuction to check if there is data in the receivedDate field, then leave it alone?
PS.

I don't know if I need the global $conn; there or not.

greggk author 10/30/2009

Ok, I've answered a few of my own questions today, however could someone tell me why this one is not working?
if (empty($values["receivedDate"])) {
if ($values["receivedCK"] > 0) {

$values["receivedDate"] = now();

}
}
I think I got the php code correct. It is supposed to check if the receivedDate is empty or not, and if it's empty, then it will add the current date, if it's not empty, it should leave it alone, but it's not leaving it alone. Every time it's edited, it's putting the new date in. I can't figure out why.

M
meirco 10/30/2009



Ok, I've answered a few of my own questions today, however could someone tell me why this one is not working?
if (empty($values["receivedDate"])) {
if ($values["receivedCK"] > 0) {

$values["receivedDate"] = now();

}
}
I think I got the php code correct. It is supposed to check if the receivedDate is empty or not, and if it's empty, then it will add the current date, if it's not empty, it should leave it alone, but it's not leaving it alone. Every time it's edited, it's putting the new date in. I can't figure out why.


  1. where did you put the code.?
  2. I know why youre confused. (POOR DOCUMENTATION)

    a good manual that is more then a list of features would have explained WHY you cant update values on the fly.

    when to use what events and why. so JANE/SERGEY how about it. explain to us when to use what events and why

    thanks

greggk author 10/31/2009

I'm putting the code in the Edit events before record updated.
I do wish there was more documentation. I do find a lot of information in the forums, but this particular issue, I don't know why I can't get it to work properly. The code seems to be good, but it's just not doing what it's supposed to be doing.

J
Jane 11/2/2009

It's difficult to tell you what's happening without seeing actual files.
Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error.

greggk author 11/2/2009

I did post the program and opened up a ticket, but I may have figured something out.

The field that I'm changing I had to read only, because I did not want the user to be able to change the date after it was checked.

I changed the field to simple date, and now one of my codes work.

if ($values["receivedDate"] < 1){
if ($values["receivedCK"] > 0) {

$values["receivedDate"] = now();

}

}

return true;
It works fine, however the user on the edit page can edit that field to whatever they want to, and that was not my intention.

J
Jane 11/3/2009

Hi,
readonly values are stored in the $oldvalues array only:

if ($oldvalues["receivedDate"] < 1)

...
greggk author 11/4/2009



Hi,
readonly values are stored in the $oldvalues array only:

if ($oldvalues["receivedDate"] < 1)

...



WoW, unbelievable. I was only missing something that simple!!! :-\
Anyway, all is working as it should now.