Categories
HTML

Problem: When submitting a form, seems like another form gets submitted

Actually, I had two forms on the same page, one with the GET method (let’s call it get_form), the other with the POST method (we’ll call it post_form). When I pressed the submit button of get_form it seemed that the post_form got submitted. In fact, all the variables in get_form and post_form were passed with the POST method.

So the natural thing that came into my mind was that the two forms were intersecting. But how? I knew for sure they were separate forms because get_form was in a file that I was including in the file that contained post_form, after post_form.

After verifying the HTML source over and over again I finally solved the mistery. There was a stupid mistake I made: I did not close post_form properly. Instead of using the form closing tag </form> at the end of post_form, i put the form opening tag <form> and every time I checked for the problem, I missed an important detail: the lack of the slash sign.

Conclusion: When opening a HTML element, make sure to close it accordingly.