Jump to content

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


Yang

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.

Link to comment
Share on other sites

  • 2 weeks later...

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!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated