Jump to content
Yang

how to execute php script in a <javascript> block?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines