1

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?

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Can I do not use the <form>?
You can make use of ajax ... means you must send request to server form HTML

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.