Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#789035
Hello there,

I am a newbie to processmaker environment. I have a requirement to implement a search functionality for custom pluggin.
I have successfully created a custom pluggin, however I need to understand the routing mechanisim (linking) from the class.dashletname.php to the dashletname.html file.
I need to fetch the search text from the dashletname.html file, process it in the class.dashletname.php file and display the search result back in the dashletname.html file.


Any help would be appreciated.

Thanks.
#789040
Hello,

When you enable a dashlet for your plugin you get dashlet<plugin-name>.html file in views folder and class.dashlet<plugin-name>.php file in the classes folder of the plugin main folder.
To exchange data between the two files, follow the steps:
* In dashlet<plugin-name>.html file write your required HTML code and use XMLHttpRequest to reach the function in .php file.
You can refer to the following HTML code:
Code: Select all
<input name = "search" id= "search">
<button id='sub' onclick="operation(this.id)">Submit</button>
<div id="container"/>
And following javascript:
Code: Select all
{literal}
<script>

function operation(id){
var val = document.getElementById("search").value;
callAjax(val);
}

function callAjax(val){
console.log(val);
    var http = new XMLHttpRequest();
    var url = "../<plugin-name>/justtest";
    var params = "val="+val;
    http.open("POST", url, true);
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.onreadystatechange = function() {
        if(http.readyState == 4 && http.status == 200) {
        var container = document.getElementById("container");
        container.innerHTML = "";
        var input = document.createElement("input");
        input.name = "result";
        input.value = http.responseText;
        container.appendChild(input);
}
    }
    http.send(params);
    }
</script>
{/literal}
* In the above code enter the URL to the justtest.php file, which is a PHP file in the plugin's main folder.
* Create an object of the class(from class.dashlet<plugin-name>.php file) in justtest.php file and call the required function.
Refer the following for justtest.php :
Code: Select all
<?php
require_once ("classes/class.dashlet<plugin-name>.php");
$call = new dashlet<plugin-name>();
$call->printing($_POST['val']);
?>
* Create your required function (like search functionality) in the class.dashlet<plugin-name>.php file.
function in class file can be :
Code: Select all
public function printing($val){
		echo $val;
	} 
Modify your function and HTML code according to the requirement.

Hope this helps.
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]