Roundcube Community Forum

 

How to call php function from javascript

Started by iBem, June 15, 2021, 06:46:33 PM

Previous topic - Next topic

iBem

Hi
I am trying to call my php function from javascript file.
This is what I have
php file:

function init()
{
     $this->include_script('client.js');
     $this->register_action('plugin.test', array($this, 'test'));
}
function test($args)
{
    echo("<script>console.log('PHP: " . "js is working" . "');</script>");
}

js file:

rcmail.http_post('plugin.test');


When I run this I get an error:

jquery.min.js?s=1612812585:36
POST http://localhost/roundcube/?_task=mail&_action=plugin.test 500
(Internal Server Error)

How should this be done correctly and could I also call javascript function from php file ?




SKaero


iBem

Quote from: SKaero on June 16, 2021, 12:58:54 AM
The problem is your PHP is invalid, echo isn't a function https://www.php.net/manual/en/function.echo.php

But if I call my test function inside my php file the echo will print text to console. And I get the POST error even if the test function is empty.

SKaero

Did you post the full plugin PHP file? What is in the Roundcube error log?