This topic is locked

Trying to use popup to display message generated in AfterAdd/AfterEdit

11/25/2026 09:21:28
PHPRunner General questions
G
GaryW author

I have a page that adds/edits an enquiry record. One of the fields is the person to whom the enquiry has been assigned. When that is set an email notification gets sent to that person informing them. If it changes then two email sget sent, one informing the new assignee and one informing the old assign that they no longer need to take action. This is done in the AfterAdd/AfterEdit events since I wanted to ensure the "Save" was complete.

If there is an issue with the email sending (be it validation or something more serious) a message is displayed on the Add/Edit screen. This is fine except when the add/edit is displayed in popup mode like it is when the page gets opened from the master/child list drilldown.

I tried added a custom save button that triggered the the original save then checked for a proxy value containing the error, so in AfterAdd/Edit I added this code:

$pageObject->setProxyValue("NotifyError","The data was successfully saved, but the notification email(s) could not be sent because:
" . $rv_msg);
$pageObject->stopPRG = true;

My custom save button code looks like this:

Client Before:
// Trigger the save
$('a[id^="saveButton"]').click();

// Did we get a message to display?
if(proxy["NotifyError"]) {
params["msg"] = proxy["NotifyError"];
} else {
params["msg"] = "X"; // DEBUG only to see if we get a message at all
}
return true;

Server:
$result["msg"] = $params["msg"];

Client After:
if(result["msg"] > "") {
Swal.fire({
icon: "warning",
title: "Email Notifications",
text: result["msg"],
showConfirmButton: true
// timer: 1000
});
}

I do get a sweetalert but just with "x" as the text so the proxy value is not making it through. I suspect that I am misunderstanding the flow of events. Interestingly the sweetalert only opens when the add/edit is opened on popup from the master/child list drilldown. When opened full screen I don't get the sweetalert popup.

Any ideas/advice appreciated. I hope I've explained it clearly enough - apologies if not.

D
DMORT 11/25/2026

It looks like it could be a timing issue with your custom button’s Client Before JavaScript. When you trigger the save click, JavaScript immediately moves on to check proxy["NotifyError"] before the server has finished saving the record and running AfterAdd/AfterEdit—so the proxy value isn't set yet and it defaults to "X".

G
GaryW author 11/25/2026

Did a few tests and it could be related to the sequence of the events. I also ready the section in the manual that says setProxyValue should be used in the BeforeProcess event.
My testing has shown that my custom button ClientBefore section gets the proxy value if it is set in (just showing the Edit event names here for simplicity) :

Before Display
Edit Page: Before Process
Edit Page: Before SQL Query
Process Record Values

I also saw in the manual in the After Edit this note:

Note: If you need to display a message on the page or pass a variable value to JavaScript, you need to add the following to the end of your event code:
$pageObject->stopPRG = true;

Any ideas what this does?

D
DMORT 11/25/2026

$pageObject->stopPRG = true; disables PHPRunner's normal Post/Redirect/Get (PRG) behavior following a successful save, which should allow messages and proxy values generated in AfterEdit to be passed back to the client.

I don't believe that makes the Save operation synchronous, though. Your additional testing seems to support the timing issue, since all four events you identified populate the proxy value before your custom button is clicked.

Have you tried eliminating the custom Save button and checking for the proxy value in the Edit page's JavaScript OnLoad event instead?

if (proxy["NotifyError"]) {
Swal.fire({
icon: "warning",
title: "Email Notifications",
text: proxy["NotifyError"]
});
}

Keep your existing AfterEdit code, including stopPRG = true, and use the standard Save button. For testing purposes, you could temporarily set the proxy value to a hardcoded error message to eliminate the email notification logic as a variable.

I would first test this by opening the Edit page in full-screen mode and then repeat the test using the master/child drilldown popup.

If it works in full-screen mode but not in popup mode, it may indicate that the remaining issue is how PHPRunner handles closing the popup after a successful save.

Might help isolate the issue.