Yang Posted June 17, 2018 Share Posted June 17, 2018 hi guys, add_hook('ClientAreaHeadOutput', 1, function($vars) { return <<<HTML <script type="text/javascript"> $( document ).ready(function() { $("#someElement").click(function(){ // How to insert php code here????????????????????????????? <?php $value = 'ttt'; ?> //This is not work, what should I do? }); </script> HTML; }); I have tried to directly insert php code in javascript block, but it doesn't work. What should I do? Can someone help me. 0 Quote Link to comment Share on other sites More sharing options...
bellafronte Posted June 19, 2018 Share Posted June 19, 2018 Maybe you can use the jQuery.get() to Load data from the server using a HTTP GET request. jQuery.get() - https://api.jquery.com/jquery.get/ jQuery get() Method - https://www.w3schools.com/jquery/ajax_get.asp 0 Quote Link to comment Share on other sites More sharing options...
TomoTech Posted June 27, 2018 Share Posted June 27, 2018 It looks like your confusing a PHP Hook with javascript. add_hook('ClientAreaHeadOutput', 1, function($vars) { return <<<HTML <script type="text/javascript"> $( document ).ready(function() { $("#someElement").click(function(){ // How to insert php code here????????????????????????????? <?php $value = 'ttt'; ?> //This is not work, what should I do? }); </script> HTML; }); The above code in GREEN is already PHP If you just want to execute PHP without returning anything then try the hook like this: add_hook('ClientAreaHeadOutput', 1, function($vars) { $value = 'ttt'; //This won't do anything it's just setting a PHP string when the ClientAreaHeadOutput hook is called //You can do things here like MYSQL & use the variables stored in $vars if there is any. }); If you want to run PHP and then pass parameters back to the clients area you will need to look into this: https://docs.whmcs.com/Templates_and_Custom_PHP_Logic The javascript part if that's needed you can do it on the .tpl file once you have set the {$variable} that you wanted from the PHP script. Take a look here for more info on Hooks - https://developers.whmcs.com/hooks/ Hope that helps! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.