Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

reinisk22's avatar

Forms and asynchronous requests

Hey,

I've been trying to build a quiz app for practice purposes but ran in some problems when it comes to how html and requests should interact with each other and I was hoping someone could give me some suggestions about this.

So basically I have an index page, with a single button Start. When this button is pressed I want to make a call to a POST endpoint /game/create to create a game and question models in DB and then return a json response, then take a question id from the json response and do a GET request to /questions/{questionId} endpoint which would then return a view which would display the question and answers options. When an option is selected, a submit button is available that should then do a POST request to /questions/{questionId}/evaluate which would return true/false I guess in a json format as well, and if the answer is correct, make a POST request to /question/create endpoint that returns a json with another question id that would be passed to a GET /question/{questionid} endpoint which would return a new question view again and so on.

All the endpoints by themselves are working well, but I can't figure out how to make them work together when trying the create the UI. For example, my index page has a form with the submit button, but I have no idea what action I should use there because I want to make 2 asynchronous requests from the same page, and my questions page also has the same issue but I need to make 3 asynchronous requests instead.

Also, I was originally thinking of doing all this with laravel/php but it seems like I need to use JS for the async requests, so my question is - Is using js here is the best option or I can somehow manage with only php/laravel?

Thank you for your time!

0 likes
6 replies
reinisk22's avatar

@Tray2 Thank you, this looks pretty cool! I went had a quick glance over the docs and I didn't notice anything about forms and async requests and it seems like I don't actually need controllers for this at all. Is this how it's meant to be used?

Please or to participate in this conversation.