Should all form elements for a form be in a single div?

My layout file is like this..

<div class = "wrapper">
     <div class = "main">
            <div class = "controller_name">
                       #printing the controller name
            </div>
            <div class = "content">
                     <%= yield%> #THIS IS WHERE THE NEW.HTML.ERB IS
RENDERED
            </div>
      </div>
      <div class ="sidebar">
               <div class = "sidebox">
                          <%= yield :sidebox_1%>#SOME FORM ELEMENT ARE
RENDERED IN HERE
                </div>
                <div class = "sidebox">
                          <%= yield :sidebox_2%>#SOME FORM ELEMENT ARE
RENDERED IN HERE
                </div>
       </div>
</div>

If you notice, ive mentioned that some form elements are rendered in
the "sidebox" divs. If instead i yield them in the "content" div
alongwith the rest of the form, everything works fine.

I figured maybe its because all the fields do not fall between the
form_for and end tags. So i tried something like this

/views/projects/new.html.erb
<% form_for @project do |f| %>
    <%= f.error_messages %>
  <% content_for :formfields do%>
    <%=render :partial => "project", :locals => {:f => f}%>
      <p>
       <%= f.submit "Save as Draft" %>
    </p>
  <% end %>
<% end %>

/views/layouts/application.html.erb

<div class="wrapper">
    <%= yield%>
    <div class="main">
      <div class="controller_name">
        <h1><%= controller.controller_name.capitalize %></h1>
      </div>

      <div class="content">
        <% flash.each do |key, msg| %>
              <%= content_tag :p, msg, :id => key, :class => 'flash'
%>
        <% end %>
        <%= yield :formfields%>
      </div>
    </div>

    <div class="sidebar">

      <div class="sidebox">
        <%= yield :sidebox1 %>
      </div>

      <div class="sidebox">
        <%= yield :sidebox2 %>
      </div>

      <div class="sidebox">
        <%= yield :sidebox3 %>
      </div>
    </div>
    <div style="clear:both;"></div>
  </div>

views/projects/_project.html.erb

...
...
<% content_for :sidebox1 do%>
...
...
<% end %>
<% content_for :sidebox2 do%>
...
...
<% end %>
<% content_for :sidebox3 do%>
...
...
<% end %># "..." representing form fields.

This way, the form fields are yielded into a div "content" which is
part of a larger div "wrapper" that yields the rest of the content
(including the form_for and end tags) (did this only for testing, do
not plan to structure my page this way). In any case, that did not
work either. The "Submit" button did nothing. The form was rendered
but clicking the Submit button did not submit anything.
Any suggestions?

I figured maybe its because all the fields do not fall between the
form_for and end tags.

No kidding. For all the "magic" in Rails, you still need to create
valid markup. :slight_smile:

The "Submit" button did nothing. The form was rendered
but clicking the Submit button did not submit anything.
Any suggestions?

Sure, validate your page; if you're still having problems after that,
check the page for JS problems with FireBug. Or post a URL here.

HTH,