synopsa
synopsa

Reputation: 75

Can I nest form tag inside form?

I have a situation where I have to nest form tag inside form because of HTML flow but it can't be done. Are there any alternatives for this?

                <tr class="first last">
                  <td class="a-right last" colspan="50"><button onclick="setLocation('#')" class="button btn-continue" title="Continue Shopping" type="button"><span>Continue Shopping</span></button>
                    <%= button_tag class: 'button btn-update', id: 'update-button' do %>
                      <%= Spree.t(:update) %>
                    <% end %>
                    <%= form_tag empty_cart_path, method: :put do %>
                      <%= submit_tag Spree.t(:empty_cart), class: 'button btn-empty' %>
                    <% end %>
                  </td>
                </tr>
                </tfoot>

          <%= form_for @order, url: update_cart_path, html: { id: 'update-cart' } do |order_form| %>

            <%= render partial: 'form', locals: { order_form: order_form } %>
          <% end %>
        <% end %>

button_tag should be inside form_for form, but if I set it like this:

                <td class="a-right last" colspan="50"><button onclick="setLocation('#')" class="button btn-continue" title="Continue Shopping" type="button"><span>Continue Shopping</span></button>
                    <%= form_for @order, url: update_cart_path, html: { id: 'update-cart' } do |order_form| %>
                    <%= button_tag class: 'button btn-update', id: 'update-button' do %>
                      <%= Spree.t(:update) %>
                    <% end %>
                    <%= form_tag empty_cart_path, method: :put do %>
                      <%= submit_tag Spree.t(:empty_cart), class: 'button btn-empty' %>
                    <% end %>
                  </td>
                </tr>
                </tfoot>


            <%= render partial: 'form', locals: { order_form: order_form } %>
          <% end %>
        <% end %>

it's not working

Upvotes: 0

Views: 417

Answers (2)

Smek
Smek

Reputation: 1208

If I'm correct you like to have that empty_cart button aligned with your update button. In Rails you can create a link that does an update or post or whatever you like. You can do something like:

<%= link_to Spree.t(:empty_cart(_method: 'put')), empty_cart_path, class: 'button btn-empty', method: :post %>

Upvotes: 1

Roman Kiselenko
Roman Kiselenko

Reputation: 44370

Can I nest form tag inside form?

You cannot nest form tags.

It is wrong. It won't work because it is wrong. Most browsers will only see one form.

https://www.w3.org/TR/html5/forms.html#the-form-element

Content model: Flow content, but with no form element descendants.

Upvotes: 1

Related Questions