Form doesn't take me to action url when submitting

When I submit my form it doesn’t take me to the right url, it instead just stays on the same url and adds the params to it. Like this: /todo?message=themessage rather than what it should be as /todo/add

<form>
<div class="form-group" action="/todo/add" method="POST">
     <label for="message">Add new todo message</label>
     <input type="text" class="form-control" name="message" id="message">
     <button type="submit" class="btn btn-primary">Add</button>
</div>
</form>

In my /todo/add url, I have a php script that is assigned to that route, which just echos a string and nothing else to see if the form hit that url, however it does not and just stays on the same page with the params.

>Solution :

You almost have it. All you need to do is to move the "action" and "method" attributes into the form tag instead of the div.

Since you don’t have the "action" in the form tag, the default behavior is to submit the form to the same page.

Leave a Reply