John Davidson

php - Form doesn't take me to action url when submitting

0 comments
Message:


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.



My Answer:
The issue here is that you are not using the correct attributes in your form tag. The action and method attributes should be inside the opening form tag, not inside a div tag.

Here is the corrected form code:

html









By moving the action and method attributes to the form tag, the form should now submit to the correct URL.

Rate this post

5 of 5 based on 9279 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us