Example of Page_DataRendering

Tips submitted by PHPMaker users
Post Reply
ldozois

Example of Page_DataRendering

Post by ldozois »

V.8

The Page_DataRendering server event allows you to place a custom message directly above the field title column. One of my project uses multi-pages. The student's name appears in the view and edit screens on the first page, but is, of course, is not visible under the other 6 tabs where the remaining pages of data are shown.

My client wanted the name visible at all times. The page data rendering event made it quick and easy work. Here is the code I used for the View and the Edit pages:

View Page

// Page Data Rendering event
function Page_DataRendering(&$header) {

	global $student;
	$header = "Viewing Record of: ".$student->First_Name->ViewValue .' '. $student->Last_Name->ViewValue;
	if ($student->Marital_Status->ViewValue    == 'Married Filing Jointly')
	{
	   $header .= ' & '. $student->Spouse_First_Name->ViewValue .' '. $student->Spouse_Last_Name->ViewValue ;
	}

}

And for the Edit Page:

// Page Data Rendering event
function Page_DataRendering(&$header) {
 global $student;
	$header = "Editing Record of: ".$student->First_Name->EditValue .' '. $student->Last_Name->EditValue;
	if ($student->Marital_Status->EditValue    == 'Married Filing Jointly')
	{
	   $header .= ' & '. $student->Spouse_First_Name->EditValue .' '. $student->Spouse_Last_Name->EditValue ;
	}
 

}

Notice the global $student. This makes the student data available to the function. In the view page, $student->Last_Name->ViewValue is in scope, while in the edit page, $student->Last_Name->EditValue is in scope.

That's all there is to it.


leeb9334
User
Posts: 4

Post by leeb9334 »

Thanks for the tip! This helped me even in Version 10. Though I needed to implement an optional/required password field on Edit page. So, if a user was created, a password is required (Form_CustomValidate) but if a user was being edited, the Password field had to be set to empty so it would be optional. Then when edit form was submitted, I hooked into RowUpdating and checked if password empty then unset the variable so it wouldn't touch the database.

My code as follows:

Row_Inserting:
if (isset($rsnew["password"]) && !empty($rsnew["password"])){
$rsnew["password"] = password_hash($rsnew["password"], PASSWORD_DEFAULT);
}

Row_Updating:
if (isset($rsnew["password"]) && !empty($rsnew["password"])){
$rsnew["password"] = password_hash($rsnew["password"], PASSWORD_DEFAULT);
}else{
unset($rsnew["password"]);
}

Form_CustomValidate:
$rs = $this->GetFieldValues("FormValue"); // Get the form values as array


if ( !isset($rs["password"]) || empty($rs["password"]) ) {
    // Return error message in $CustomError
     $CustomError = "Password must be set";
    return FALSE;                         
 } else {                                  
     return TRUE;
 }    

Page_DataRendering:
global $affiliates;
$affiliates->password->EditValue = "";

Hope this helps someone in the future.

Thanks!


Post Reply