Hi,
I'd like test for a condition in a table's hook file before_insert and/or before_update functions and accordingly display a pop (modal) message to the user. How can I do that?
Your help would be appreciated.
Thanks
How to produce a pop up message based on a test in a hook script
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: How to produce a pop up message based on a test in a hook script
before_insert and before_update hooks can't send output directly to the browser currently (but we plan to change that in future releases). For now, here is a trick: In the before_* hook, save your popup message contents to a session variable:
Then, in the tablename_footer hook, display the message and clear the session variable:
Code: Select all
$_SESSION['cancel_reason'] = "You can't perform this operation because of xyz.";
Code: Select all
if(!empty($_SESSION['cancel_reason'])) {
ob_start();
?>
<script>$j(function() {
modal_window({ message: <?php echo json_encode($_SESSION['cancel_reason']); ?> });
})</script>
<%%FOOTER%%>
<?php
$footer = ob_get_clean();
unset($_SESSION['cancel_reason']);
}
AppGini plugins to add more power to your apps:
- DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
- Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
- Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.
-
- Veteran Member
- Posts: 54
- Joined: 2016-03-21 19:33
Re: How to produce a pop up message based on a test in a hook script
Thank you so much!
Re: How to produce a pop up message based on a test in a hook script
Hi there,
Danny, is it work? If yes, could you show us your example file? Because it's not worked on me.
Danny, is it work? If yes, could you show us your example file? Because it's not worked on me.
Re: How to produce a pop up message based on a test in a hook script
Okay i found it
function arizali_urun_takibi_footer($contentType, $memberInfo, &$args) {
$footer='';
switch($contentType) {
case 'tableview':
$footer='';
break;
case 'detailview':
if(!empty($_SESSION['cancel_reason'])) {
ob_start();
?>
<script>$j(function() {
modal_window({ message: <?php echo json_encode($_SESSION['cancel_reason']); ?> });
})</script>
<%%FOOTER%%>
<?php
$footer = ob_get_clean();
unset($_SESSION['cancel_reason']);
}
break;
case 'tableview+detailview':
$footer='';
break;
case 'print-tableview':
$footer='';
break;
case 'print-detailview':
$footer='';
break;
case 'filters':
$footer='';
break;
}
return $footer;
}
function arizali_urun_takibi_before_insert(&$data, $memberInfo, &$args) {
$_SESSION['cancel_reason'] = "You can't perform this operation because of xyz.";
return TRUE;
}
function arizali_urun_takibi_footer($contentType, $memberInfo, &$args) {
$footer='';
switch($contentType) {
case 'tableview':
$footer='';
break;
case 'detailview':
if(!empty($_SESSION['cancel_reason'])) {
ob_start();
?>
<script>$j(function() {
modal_window({ message: <?php echo json_encode($_SESSION['cancel_reason']); ?> });
})</script>
<%%FOOTER%%>
<?php
$footer = ob_get_clean();
unset($_SESSION['cancel_reason']);
}
break;
case 'tableview+detailview':
$footer='';
break;
case 'print-tableview':
$footer='';
break;
case 'print-detailview':
$footer='';
break;
case 'filters':
$footer='';
break;
}
return $footer;
}
function arizali_urun_takibi_before_insert(&$data, $memberInfo, &$args) {
$_SESSION['cancel_reason'] = "You can't perform this operation because of xyz.";
return TRUE;
}