user4757174
user4757174

Reputation: 426

Is it bad to wrap entire html document in <form>?

I have a database front-end that has several text fields for input on top of the page using post, and a pagination bar at the bottom of the page that uses the post method as well.

I've encapsulated the top inputs in

<form method = 'post'>

<Body>

 //Inputs

//Table contents


//Pagination bar buttons

</Body>


</Form>  

, but I've also extended the form so the form extends to the bottom of the document. (Database table is returned in middle of document) If I start a new form tag, the request will not include the previously entered text fields on the top, only the input inside the bottom form, so I can't use two forms.

<Html>
<Form method ='post'>

//Inputs 
</Form>
//Table results

<Form method = 'post'>
//Pagination bar buttons
</Form> 
</Html>

This will not work. I want to ask, is it ok to encapsulate entire html doc in form tag? I don't want the client to send the entire doc in post or something.

Upvotes: 1

Views: 822

Answers (2)

borbesaur
borbesaur

Reputation: 691

The only thing(s) that will be submitted in a form are values associated with input tags. So the entire document won't be submitted in the form. Only values associated with inputs.
Whether or not your design is "a bad idea" is hard to tell with the information given. I am unable to tell why exactly your pagination bar needs to be a form at all (rather than a link) but again, if you're worried about the entire document submitting in the form, that won't happen.

Upvotes: 1

tmslnz
tmslnz

Reputation: 1813

If you mean this, that's fine:

<!DOCTYPE html>
<html>
<head>
    <title>This is OK</title>
</head>
<body>
    <form>
        Everything
    </form>
</body>
</html>

But

<form>
    <!DOCTYPE html>
    <html>
    <head>
        <title>Yes this is bad</title>
    </head>
    <body>
        Something
    </body>
    </html>
</form>

or

<!DOCTYPE html>
<form>
    <html>
    <head>
        <title>Yes this is bad</title>
    </head>
    <body>
        Something
    </body>
    </html>
</form>

Is just invalid.

Upvotes: 2

Related Questions