qg_java_17137
qg_java_17137

Reputation: 3569

Html Button trigger PHP code

I have a demo.php, in it I have a button:

<?php

include('../library/Requests.php');

Requests::register_autoloader();

function get_data(){
    $request = Requests::post('http://localhost:8000/api/groups/list/', array(), null);

    var_dump($request);
}

?>

<button>Click Me</button>

How can I trigger the get_data method in my demo.php? Who can tell me the solution?

Upvotes: 1

Views: 38

Answers (1)

Veshraj Joshi
Veshraj Joshi

Reputation: 3579

You have you to look simple things...

<?php

include('../library/Requests.php');

Requests::register_autoloader();
// check whether form is submitted or not on same page if submitted then call get_data() function
if(isset($_POST['submitBtn']))
{
     get_data();
}
function get_data(){
    $request = Requests::post('http://localhost:8000/api/groups/list/', array(), null);

    var_dump($request);
}


?>

// make form that could send request
<form action="" method="post">
     <button name="submitBtn" type="submit">Click Me</button>
</form>

Upvotes: 2

Related Questions