When the form is submitted, the action URL fails to jump correctly.
P粉674876385
2023-08-28 22:30:40
<p>When I submit the form, instead of taking me to the correct URL, it just stays on the same URL and adds the parameters to it. Like this: /todo?message=themessage instead of /todo/add</p>
<pre class="brush:php;toolbar:false;"><form>
<div class="form-group" action="/todo/add" method="POST">
<label for="message">Add new to-do message</label>
<input type="text" class="form-control" name="message" id="message">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form></pre>
<p>In my /todo/add URL I have a php script assigned to that route and it just echoes a string to see if the form hits the URL, but it doesn't, it just Stay on the same page with parameters. </p>
Put action='' and method='' in the form tag instead of the div tag
You almost did it. All you need to do is move the "action" and "method" attributes into the form tag, not the div tag.
Since you don't have "action" in the form tag, the default behavior is to submit the form to the same page.