Reputation: 1
I have a question about correct nesting and syntax with using form element in HTML. I understand basics but is it okay to put there divs, paragraphs, spans, etc.? Because using nice CSS need sometimes more elements and because I am front-end learner I am not sure if these elements inside form influence some data and inputs. If you have some examples of using very advanced HTML in forms I would really appreciated some already used HTML real examples. Also if you can explain how it works with data collecting from forms, it could also help me understand this nesting. Btw: is it important to have button inside the form or it can be outside this element? Thans for any answer.
Upvotes: 0
Views: 204
Reputation: 2619
First place to go when you want to know anything about HTML/CSS and JavaScript in the browser is MDN. In your case: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Form
As you can see there, forms can indeed include any types of elements (a <form>
behaves like a <div>
for all visual design purposes), except for nested <form>
elements
Data collection for a form is typically (as in plain HTML/HTTP) made by sending a request to the URL given in its action
property. How this request is exactly formed can be controlled through the use of attributes method
and enctype
.
Basically, the request body (for POST) or query string (for GET), will contain all data inside the form as key/value pairs, where the keys are the name
attribute of the input fields, while the value is their value
attribute.
This can vary a little depending on field type. For instance a <textarea>
will send its text contents as a value instead.
The sending of this request (and browser navigation) is triggered when the user clicks a submit
button on the form (either <input type="submit">
or <button>
). This is called submitting the form.
Upvotes: 1
Reputation: 177
is it okay to put there divs, paragraphs spans etc.
Yes, that's perfectly fine.
is it important to have button inside the form or it can be outside this element?
You can have a button outside of a form - depends on what functionality you are trying to achieve.
If you have some expamle of using very advanced html in forms
Your question is quite basic so I don't know how much of an advanced example you are looking for, but you can find examples of css classes being used with forms on this Bootstrap 5 tutorial (Bootstrap is a CSS library/framework): https://getbootstrap.com/docs/5.0/forms/layout/
Upvotes: 0