Weird problem with my Flask app: my HTML submit button doesn't work with a mouse click but it DOES work when I press the enter key. What could it be? [duplicate]
Solution 1:
It is not common practice. In most cases, it offers no benefits but has a drawback: some old browsers do not support the form
attribute, so things just don’t work on them.
An input
element outside a form
element has always been permitted. Such an element just won’t participate in any form submission, if it has no form
attribute. But it can be used with client-side scripting.
The form
attribute associates, in supporting browsers, the element with a form just as if the element were inside the form. This can be useful in complicated cases where e.g. one row of a table should contain fields of a form, another row fields of another form, etc. You cannot wrap just one row inside a form, and here the attribute comes to rescue: you put a form
element inside one cell of the row and refer to that element in fields in other cells with the form
attribute.
Solution 2:
Yes, you can definitely do this as of HTML5, using the form
attribute on inputs that are located outside the form
element; just like you did.
For more details and examples, see HTML <input>
form Attribute at W3 Schools.
Solution 3:
There is nothing wrong with putting them there, and they will be available within the DOM if you are doing something with javascript, etc. but when you submit the form, the values of your fields will not be in the results submitted.