Page 1 of 1

How to produce a pop up message based on a test in a hook script

Posted: 2019-02-15 19:45
by dannybridi
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

Re: How to produce a pop up message based on a test in a hook script

Posted: 2019-02-20 13:37
by a.gneady
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:

Code: Select all

$_SESSION['cancel_reason'] = "You can't perform this operation because of xyz.";
Then, in the tablename_footer hook, display the message and clear the session variable:

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']);
}

Re: How to produce a pop up message based on a test in a hook script

Posted: 2019-02-22 14:45
by dannybridi
Thank you so much!

Re: How to produce a pop up message based on a test in a hook script

Posted: 2020-08-04 11:11
by yonder
Hi there,

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

Posted: 2020-08-04 11:30
by yonder
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;
}