Row_inserting YEAR

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mpol_ch
User
Posts: 877
Location: Switzerland

Row_inserting YEAR

Post by mpol_ch »

Hello
I am trying to insert "Year" automatically as from date (datum) I am getting allways 1970. Could you pelase help how to do this?
My field called "Datum" and I am inserting a date like: 23.08.2014 (dd.mm.YYYY). On row inserting I want to have 2014 in Jahr.

function Row_Updating($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
$rsnew["Jahr"]=date('Y',strtotime($rsnew["Datum"]));
return TRUE;
}

mpol_ch


mobhar
User
Posts: 11737

Post by mobhar »

Make sure $rsnew["Datum"] contains the correct date. If it contains blank string/value, then it will always return 1970.

Use $rsold["Datum"] instead.


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

Hello mobhar

thanks for your response. Now the following code is working fine. Do you know how can I hide the field in Grid Add or in Grid Edit?

I disabled the following fileds (Jahr, WNr, Tag) in normal "Add page"and "Edit page". But I see these fields in grid add and grid edit.

function Row_Inserting($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE
$rsnew["Jahr"]=date('Y',strtotime($rsnew["Datum"]));
$rsnew["WNr"]=date('W',strtotime($rsnew["Datum"]));
$rsnew["Tag"]=date('w',strtotime($rsnew["Datum"]))+1;
return TRUE;
}

thanks for your time.

mpol_ch


mobhar
User
Posts: 11737

Post by mobhar »

Simply put the following code in "Page_Render" server event:

if ($this->CurrentAction == "gridadd" || $this->CurrentAction == "gridedit") {
$this->Jahr->Visible = FALSE;
$this->WNr->Visible = FALSE;
$this->Tag->Visible = FALSE;
}


mpol_ch
User
Posts: 877
Location: Switzerland

Post by mpol_ch »

hello mobhar

thanks a lot for your response. I will try it.

mpol_ch


Post Reply