Hi chaps,
quick question. Is a html form tag always required when you add a form to the html? In other words if you have a form and leave out the form tag will the code still validate? I have heard some saying that a form tag is only necessary if the form passes data to the server or something like that. The reason for the question is that when I develop a web page for a CMS - sorry can't remember the name of this cms off the top of my head - it adds its own form tag straight after the body tag, whether there is a form or not, so that all the content after the body tag is effectively contained inside a form tag. The problem is that this cms accepts only 1 form tag, so if I happen to have a form in my html I can't use the tag anymore (if you try to use it the cms replaces it with a normal div, I don't know whether this is a bug that came with it or a feature)
thanks

yes, the form tag is required. And it can not be nested.
Which is likely why the CMS you use replaces it with a div tag if you have forms inside your html that it wraps.
Which itself is nasty, as you might have multiple forms on a page, with the same form elements on each, being submitted under different names to the server, which would get broken by this system.

So be very careful what you do, as this CMS may well break your html.

thanks jwenting.

as you might have multiple forms on a page, with the same form elements on each, being submitted under different names to the server, which would get broken by this system.

That did cross my mind, but for now I don't seem to have multiple forms luckily, all my forms are just divided into different section and they all have one submit button. If the client wants to add multiple forms, I have no idea how that, and if, can be handled.

Also I was wondering, isn't this way - adding a form tag straight after the body tag - of handling content semantically incorrect? I mean I assume the code validates but having what's not a form inside a form tag doesn't strike me to be the best thing to do

If your CMS allows you to use JavaScript and ajax to post data, you can get away without the form tag.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.