annoyingnewbie
annoyingnewbie

Reputation: 163

Is it possible to code a form over multiple divs?

I'm coding an email subscription form (api's proving a nightmare on their own) and I was wondering if it is possible to write a form across divs, as per below...

<div id="topsubscribe_label">STAY UP TO DATE, JOIN OUR MAILING LIST: </div>     

<form id="signup" action="<?=$_SERVER['PHP_SELF']; ?>" method="get">
<div id="subforminputs">
<input type="email" name="email" id="email" class="toptextinput" value="" placeholder="[email protected]"/><br />
</div>      

<div id="topsubscribe_submit">
<input type="submit" id="topregisterButton" name="submit" class="textinput" value="Subscribe" />
</form>         
</div>

Will this break the form? Is there another (simple) way to do this?

Upvotes: 0

Views: 4547

Answers (3)

the_lotus
the_lotus

Reputation: 12748

You can do this

<div>
  <div>
  <form>
  </form>
  </div>
</div>

You can also do this

<form>
  <div>
  </div>
  <div>
  </div>
</form>

But you cannot do this

<form>
  <div>
</form>
  </div>

Browser won't show any errors, you might have different output. Each browser handles these error diffrently.

Upvotes: 3

svidgen
svidgen

Reputation: 14312

This is acceptable:

<div>
  <form>
    <div><input /><input /></div>
    <div><input /><input /></div>
  </form>
</div>

This is not:

<div>
  <form>
    <input /><input />
</div>
<div>
    <input /><input />
  </form>
</div>

It may be worth noting that overlapping tags as in the 2nd example is invalid for all tags; not just form tags.

Upvotes: 2

kirelagin
kirelagin

Reputation: 13626

If you just want to group some fields, you can use fieldset element.

Upvotes: 1

Related Questions