How to add JavaScript code on server side?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ppinto
User
Posts: 138

How to add JavaScript code on server side?

Post by ppinto »

Back in v2020, I could add JavaScript code to a global PHP variable in any server-side event and just add this to a client-side startup script like this:

<?php 
global $javascript_to_run;
echo $javascript_to_run; 
?>

In v2023, this is not possible, as it turns an error when generating: "Error: PHP code is not allowed in global Client or Startup Script."
How can I add JavaScript code that depends on conditions that are evaluated server-side, say in a Row_Rendering event?


mobhar
User
Posts: 11776

Post by mobhar »

It actually depends on what exactly did you want to achieve? Why did you need to put PHP code inside the Global Client Scripts? What condition did you mean? Please explain it in more detail.


ppinto
User
Posts: 138

Post by ppinto »

I need that decision to be made during server-side events like Row_Rendering, for example.
I put the PHP code above in the client script just to echo a string of javascript that was previously created during the server-side events, as needed (loads of reasons for that).
Will gladly change the approach as long as the decision to add javascript code can be made server-side. Any way to achieve that?


mobhar
User
Posts: 11776

Post by mobhar »

If you meant you want to display something from server event in client side, then you may use SetClientVar global function. For more info, please read Some Global Functions.


ppinto
User
Posts: 138

Post by ppinto »

Thanks for the suggestions, guys. Using SetClientVar() did it for me.
Thanks for pointing me in the right direction.


Post Reply