Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

form_for closes <form> tag

I have a strange situation happening on a page where my <form> tags are being closed immediately, leaving the form's contents on their own and not useful.

Here's the basic ERB:

<%= form_for(@review) do |f| %>
   <%= render 'apply/review_form', :locals => {:f => f} %>
   <%= f.text_field :notes %>
<% end %>

Seems simple, right? I have tried the partial on its own; the text_field on its own; a different version using form_tag, but nothing works.

The HTML looks like this:

<div id="reviewContainer">
  <form accept-charset="UTF-8" action="/reviews" class="new_review" id="new_review" method="post">
  </form>
  <div style="margin:0;padding:0;display:inline">
    <input name="utf8" type="hidden" value="✓">
    <input name="authenticity_token" type="hidden" value="dJSuLMfhBSVKAM3Buwe1NjtBedSLQl062/+oliGbBfE=">
  </div>
  <input id="review_notes" name="review[notes]" size="30" type="text">
  <div class="clear"></div>
</div>

Any ideas? It seems so simple I can't understand why it wouldn't be working!


Possibly helpful information

This form is not the only form on the page, and it is enclosed in a JQuery Tools Scrollable.

like image 793
sscirrus Avatar asked May 23 '11 09:05

sscirrus


People also ask

What is closing form tag?

An opening tag begins a section of page content, and a closing tag ends it. For example, to markup a section of text as a paragraph, you would open the paragraph with an opening paragraph tag <p> and close it with a closing paragraph tag </p> (closing tags always proceed the element with a /).

Does the form tag have a closing tag?

'Form' does have a closing tag, 'Input' does not..

What is difference between Form_for and Form_tag?

You use form_for with a model and form_tag for custom URLs. Both generate HTML for a form .


1 Answers

I had this problem and figured it out. For me, it was because I was rendering the form in an invalid place. Specifically, I had some content like this:

<table>
  <tr>
    <td>
      Stuff I might want to edit
    </td>
    <div style="display: none">
      <%= form_for thing_i_might_want_to_edit %>
        ...
      <% end %>
    </div>
  </tr>
</table>

Moving the hidden div (and the form inside it) into the tag fixed the problem.

like image 50
Jeff Gran Avatar answered Oct 18 '22 21:10

Jeff Gran