problem with Page_Load & Row_CustomAction events

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

problem with Page_Load & Row_CustomAction events

Post by mansour »

Hi,

I use both Page_Load & Row_CustomAction events with my project. I receive a warning message when I execute my custom action.
codes:

// Page Load event
function Page_Load() {
//echo "Page Load";
$this->CustomActions["addpatient"] = new cListAction("addpatient", "تائید بیمار", IsLoggedIn(), EW_ACTION_AJAX, EW_ACTION_SINGLE, "تائید و ثبت مشخصات بیمار؟", "glyphicon glyphicon-star ewIcon");
}

// Row Custom Action event
function Row_CustomAction($action, $row) {
// Return FALSE to abort
if ($action == "addpatient") { // Check action name
$rsnew = ["Approved" => "Y"]; // Array of field(s) to be updated
$result = $this->Update($rsnew); // Note: The Update() method updates the current record only
if (!$result) { // Failure
$this->setFailureMessage("Failed to update record, ID = " . $row["PatientID"]);
return FALSE; // Abort and rollback
} elseif ($this->SelectedIndex == $this->SelectedCount) { // Last row
$this->setSuccessMessage("All selected records updated.");
}
return TRUE; // Success
}
}

The confirmation message with error:

Warning: array_key_exists() expects parameter 2 to be array, null given in C:\xampp\htdocs\ptsoft\temp_patientsinfo.php on line 1243

Warning: array_key_exists() expects parameter 2 to be array, null given in C:\xampp\htdocs\ptsoft\temp_patientsinfo.php on line 1243
All selected records updated.

Codes for line 1243 :
if (array_key_exists($fldname, $this->fields) && array_key_exists($fldname, $rsold) && $this->fields[$fldname]->FldDataType <> EW_DATATYPE_BLOB) { // Ignore BLOB fields

Any idea? What's the problem?

Thanks
Mansour


kirondedshem
User
Posts: 642

Post by kirondedshem »

If you read the the documentation, you'll see that the $row value in this event indicates the array of field values for each row, this event does not call row inserting or row updating events at all, so you dont have an $rsnew array in this case, unless you define it somewhere else.

$result = $this->Update($rsnew); // Note: The Update() method updates the current record only
I dont think $this->Update() is one of those functiong you are allowed to call at anytime coz i believe its used by row updating events.
So i feel you should update this record yourself instead. besides the query isn't that long. SO do something like this

ASSUMING your table looks like
my_table:id,approved
// Row Custom Action event
function Row_CustomAction($action, $row) {
// Return FALSE to abort
if ($action == "addpatient") { // Check action name
//NOTE $row is an array of all field values in each row
$id = $row["id"];//get the primary key of this record
//update approved value of current record to Y
ew_Execute("update my_table set approved = 'Y' where id = $id");
return TRUE; // Success
}
}

NOTE: since you are updating a given column value on the list, you might want the list to refresh and show updated values after this custom action is run, so change yourpost method to postback instead of ajax. Also why dont you allow to submit multiple rows too

function Page_Load() {
//echo "Page Load";
$this->CustomActions["addpatient"] = new cListAction("addpatient", "تائید بیمار", IsLoggedIn(), EW_ACTION_POSTBACK, EW_ACTION_MULTIPLE, "تائید و ثبت مشخصات بیمار؟", "glyphicon glyphicon-star ewIcon");
}


Post Reply