Hi. I’ve create a custom file with multiple box for insert more values from db. I’ve adding also a button for submit form on same page and loading the data. Now i’m a trying to search with an select2 the data, for to make the search dynamic. I have some problem with the answer because execute Rows provides a different multidimensional array. A few suggestions?MyCustomPage.php with Header/Footer inlcluded
let’s say i solved this, as i couldn’t convert the executer array to select2 format (‘id’, ‘text’). but to use executejson I have to add the commonfiles and the echo result is dirty as well as having problems with POST. If I use a clean file and mysqli everything works fine. How can I retrieve the query result in jQuery using the built-in PHPMaker functions? If I used userfn.php for my getData code but select2 in the ‘url’ parameter does not accept variables, how could I solve?
// Get Data select2
if(!isset($_POST['searchTerm'])){
$data = ExecuteJson("select * from clientirc order by idCliente limit 10");
}else{
$search = $_POST['searchTerm'];
$data = ExecuteJson("select * from clientirc where NC like '%".$search."%' || BarCode like '%".$search."%' limit 10");
}
echo $data;
//echo json_encode($data);
also if I use POST (with common file) return 200 error
type: “POST”,
400
Bad Request
The server cannot or will not process the request due to an apparent client error.With GET returns header and footer not good
type: “GET”,
It depends on how you created your action Getdata. If you defined it by $app->get(), you should use it by HTTP GET. If you defined it by $app->post(), you should use it by HTTP POST.Read How to create routes.
I think I did not understand. PHPMaker in the compilation creates routes with the GET method? Anyway I can use GET, but the problem I get all of the page, instead of just echo.
I could create an empty file and insert (https://discourse.hkvstore.com/t/use-phpmaker-scripts-in-my-existing-website-v2021/3735/1)
require_once $ RELATIVE_PATH. “vendor / autoload.php”;
require_once $ RELATIVE_PATH. “src / constants.php”;
require_once $ RELATIVE_PATH. “src / config.php”;
require_once $ RELATIVE_PATH. “src / phpfn.php”;
require_once $ RELATIVE_PATH. “src / userfn.php”;
but I don’t really like it as a solution.
I can create a function in userfn but how can I pass the value in select2 to the url:“?”
I can also use server event Route_Action, but how can i assign value to url: “?” in select2?
I’ve change i t to, but retunr always undefined in select2 option it appears to be unable to insert values into select2 optionsdrop down menu select2 in home.php
undefined - undefined
undefined - undefined
undefined - undefined
undefined - undefined
//add a route without create a custon file with content
function Route_Action($app)
{
$app->any('/myaction', function ($request, $response, $args) {
$oldresponse = "";
if(!isset($_POST['searchTerm'])){
$data = ExecuteRows("SELECT idCliente AS id, NC AS Text, BarCode AS Code from clientirc order by idCliente limit 10");
}else{
$search = $_POST['searchTerm'];
$search = AdjustSql($search);
$data = ExecuteRows("SELECT idCliente AS id, NC AS Text, BarCode AS Code from clientirc where NC like '%".$search."%' || BarCode like '%".$search."%' limit 10");
}
return $response->withJson($data);
});
}