Getting Jquery to call Function In Hooks file

Discussions related to customizing hooks. Hooks are documented at
Post Reply
Posts: 1
Joined: 2018-11-13 16:39

Getting Jquery to call Function In Hooks file

Post by mrunne » 2018-11-13 22:26

I have the following sql update working in my after_update function in my hooks php file.
/* This will move all equipment to users new desk and add all equipment at desk */
$id = $data['selectedID'];
$newSeat = $data['CubeNum'] ;
if ($id == '557'){
sql("UPDATE `pnb_equip` SET `Location` = $newSeat WHERE `Assigned`= $id ", $eo);
sql("UPDATE `pnb_equip` SET `Assigned` = $id WHERE `Location`= $newSeat ", $eo);

This code works perfectly, except for the fact that I don't want it to run every time I update a Detail View record. With that being said, I created a Jquery script below that places a button on the detail view and it is working as expected. I know that by the working text alerts.
<?php if($selectedID){ ?>
$j('#pnb_user_dv_action_buttons .btn-toolbar').append(
'<div class="btn-group-vertical btn-group-lg" style="width: 100%;">' +
'<button type="button" class="btn btn-warning btn-lg" onclick="moveEquipment()">' +
'<i class="glyphicon glyphicon-ok"></i> Move Equipment </button>' +
<?php } ?>
function moveequipment(){
var txt;
var r = confirm("You are moving all equipment to users current Seat");
if (r == true) {
alert('Completing Move');
else {
The issue is how do I make the sql changes work by using the confirm popups?
Mr. Runne
Dev Engineer

AppGini Super Hero
AppGini Super Hero
Posts: 378
Joined: 2018-04-01 10:12

Re: Getting Jquery to call Function In Hooks file

Post by pböttcher » 2018-11-14 07:37


if you want to use jquery you would need to add an ajax call to a php file which would contain your SQL statement to be executed. You cannot directly call a function (not without additional work).

Just another idea:
Why dont you add a checkbox field that would indicate that you want to update your database with your mentioned SQL queries. In the after_update function you could react on the value of the checkbox and decide to run your SQL or not.

Post Reply