bramus / router

A lightweight and simple object oriented PHP Router
MIT License
1.09k stars 245 forks source link

Form submits a GET request without a submit-button #198

Closed jonasbirkelof closed 1 year ago

jonasbirkelof commented 1 year ago

I have a login form that looks like this.

<form>
  <button>Send</button>
</form>

No form method, no button type="submit" or anything but the form will still send a GET request.

The router looks like this:

$Router->get('/login', [LoginController::class, 'index']);

I want to use onclick="myFunction()" on the button to manage the form and then use JS inside the function to submit the form. I don't want the html to make the post request. This has worked before when I have not used a router so I suspect it has something to do with that.

Why does the form make a GET request even without a submit button?

When I look at $_SERVER['REQUEST_METHOD'] after I load the page it is GET. Does it have anything to do with that?

jonasbirkelof commented 1 year ago

I just had a brain fart... Changing the <button> to a <input type="button"> solved it.