GridAdd page row count when submit the form

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
kumar
User
Posts: 111

GridAdd page row count when submit the form

Post by kumar »

I want to execute a script only after last entry inserted in gridadd page. Not for every row.
Is any predefined method available to know how many rows having in gridadd page and current row number at the time of submit. (v11)


mobhar
User
Posts: 11737

Post by mobhar »

Simply use "Row_Inserted" server event to execute a script only after last entry is inserted in Grid-Add page.

If you want to know how many rows in Grid Add page, then simply use "Grid_Inserting" server event:

// Grid Inserting event
function Grid_Inserting() {
	// Enter your code here
	// To reject grid insert, set return value to FALSE
	$rsnew = $this->GetGridFormValues(); // Get the form values of the new records as an array of array
	//var_dump($rsnew); die(); // Print the records and end the script
	$i = 0;
	foreach ($rsnew as $row) { // Loop through the new records
		$i++;
	}
	$this->setSuccessMessage($i); // <-- you will know how many rows in the grid here
	return FALSE; // <-- this is only for check, just remove this line to proceed
	return TRUE;
}

kumar
User
Posts: 111

Post by kumar »

function Grid_Inserting() {
$rsnew = $this->GetGridFormValues();
var_dump($rsnew);
return FALSE;
}
I have filled two rows, but var_dump($rsnew) Is giving empty values as below.

array (size=2)
0 =>
array (size=7)
'SLNO' => &null
'EMPNO' => &string '' (length=0)
'EMP_NAME' => &string '' (length=0)
'PERMISSION' => &string '' (length=0)
'DEPT' => &string '' (length=0)
'RIGHTS' => &string '' (length=0)
'CURRENTTIME' => &null
1 =>
array (size=7)
'SLNO' => &null
'EMPNO' => &string '' (length=0)
'EMP_NAME' => &string '' (length=0)
'PERMISSION' => &string '' (length=0)
'DEPT' => &string '' (length=0)
'RIGHTS' => &string '' (length=0)
'CURRENTTIME' => &null

How to get form values in Grid_Inserting() event.


Webmaster
User
Posts: 9427

Post by Webmaster »

Modify function GetFieldValues() in phpfn.php of the template, change:

$values[$fldname] = &$fld->$propertyname;

to:

$values[$fldname] = $fld->$propertyname;


kumar
User
Posts: 111

Post by kumar »

Now it works. Thanks.


Post Reply