Page 1 of 1
Display popup after insert a new record in a table
Posted: 2022-07-25 08:58
by balfons
Hi!
I'm triying to display a popup after insert a new record in a table. I have searched in many forums and this is my code:
Code: Select all
function function_alert($message) {// I define the function to display the alert box
echo "<script>alert('$message');</script>";
}
//Then, I call the function in after insert of the php file. In this case is regulations_systems.php
function regulations_systems_after_insert($data, $memberInfo, &$args) {
function_alert("Hi! You added a new item. Please, check it up!");
insert_nucli($data); //This is another function I need to call after insert a new record. This one works fine
return TRUE;
}
But, nothing happens and no popup is displayed. Any ideas of what is wrong in my code? Any othen suggestion for doing this?
Thanks in advance!
Re: Display popup after insert a new record in a table
Posted: 2022-07-25 11:55
by jsetzer
Possible Reason
Well, just see the sequence of function calls when inserting a record:
- UI: You click #insert button
- Browser POSTs data to server
- AppGini code executes
before_insert()
-hook
- AppGini code inserts the record into the database
- AppGini code calls
after_insert()
-hook
(here you echo "<script>alert('$message');</script>";
- AppGini reloads the Detail View (or redirects to a different page, if configured)
Due to the immediate reload of Detail View (showing inserted record) your
echo
-command in
after_insert()
-hook does not have any effect on the newly loaded Detail View page, I guess.
Possible Solution
So, your task is to pass your
$message
from
after_insert()
-hook into the Detail View and alert it once (=not on every further load of detail view).
What about the following:
- In
TABLENAME_after_insert()
-hook populate a $_SESSION
-variable with your message
- In
TABLENALE_dv()
-hook, if $selectedID
exists, check if that $_SESSION
-variable is defined.
- If it is, append your
<script>...</script>
to $html
variable...
- and unset the
$_SESSION
variable (to avoid another alert on next DV-opening)
Re: Display popup after insert a new record in a table
Posted: 2022-07-25 12:03
by jsetzer
Starting point for your own implementation, this is working for me:
Code: Select all
function TABLENAME_after_insert($data, $memberInfo, &$args)
{
$message = "I will be displayed once after insert";
$_SESSION["DISPLAY_MESSAGE"] = $message;
return TRUE;
}
Code: Select all
function TABLENAME_dv($selectedID, $memberInfo, &$html, &$args)
{
if ($selectedID && isset($_SESSION["DISPLAY_MESSAGE"])) {
$html .= '<script>alert("' . $_SESSION["DISPLAY_MESSAGE"] . '");</script>';
unset($_SESSION["DISPLAY_MESSAGE"]);
}
}
Result

- 6e4F6eSRTm.png (5.56 KiB) Viewed 2696 times
Re: Display popup after insert a new record in a table
Posted: 2022-07-25 12:18
by jsetzer
Tipp
If your browser supports
Notification API, check out this following Notification instead of the blocking browser Alert:
Code: Select all
$html .= '<script>new window.Notification("Inserted", {body: "'.htmlentities($_SESSION["DISPLAY_MESSAGE"]).'"});</script>';
Re: Display popup after insert a new record in a table
Posted: 2022-07-26 10:36
by balfons
Hi Jan!
thanks for your quick answer! I'll implement what you suggest and let you know if it works.
Regards
Re: Display popup after insert a new record in a table
Posted: 2022-07-26 12:18
by balfons
Hi again, Jan!
I have just implemented the code you suggested in TABLENAME_after_insert and TABLENAME_dv and it works! It will be very useful for our project.
Thanks again
Re: Display popup after insert a new record in a table
Posted: 2022-07-26 16:56
by jsetzer
Thanks for your feedback.
Did you try with the Browser-Notifications? Does it work for you?