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

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
dannybridi
Veteran Member
Posts: 54
Joined: 2016-03-21 19:33

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

Post by dannybridi » 2019-02-15 19:45

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

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

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

Post by a.gneady » 2019-02-20 13:37

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

dannybridi
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

Post by dannybridi » 2019-02-22 14:45

Thank you so much!

yonder
Posts: 28
Joined: 2018-05-01 12:19

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

Post by yonder » 2020-08-04 11:11

Hi there,

Danny, is it work? If yes, could you show us your example file? Because it's not worked on me.

yonder
Posts: 28
Joined: 2018-05-01 12:19

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

Post by yonder » 2020-08-04 11:30

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;
}

Post Reply