Topic: Multiple button submit tags

Hi all,
I am trying to create a form that will have two buttons that both write information to a database.  The first button will write the information and load a new instance of the original form (page 1) using the "create" function.  The other button will write the information and load the next sequential page (page 2) using the "create_next" function.  I have tested both of these functions and they are working fine. 

Where my problem lies is that I can not get both buttons to work at the same time either they both do the same thing or one does nothing at all.  Here is the code I have in my new.rhtml file, which appears to be where the problem is.

<%= start_form_tag %>
  <%= render :partial => 'form' %>
  <%= submit_tag ('Save & Add Another', :action => 'create')  %>
  <%= submit_tag ('Next', :action => 'create_next')  %>
<%= end_form_tag %>

Thank you in advance for your help.

Re: Multiple button submit tags

If you give a name to the button, you can detect which one was clicked.

<%= start_form_tag :action => 'create' %>
  <%= render :partial => 'form' %>
  <%= submit_tag 'Save & Add Another', :name => 'save_button'  %>
  <%= submit_tag 'Next', :name => 'next_button'  %>
<%= end_form_tag %>

# in controller
def create
  #...
  if params[:next_button]
    # redirect to next action
  else
    # render form again
  end
end

Railscasts - Free Ruby on Rails Screencasts

Re: Multiple button submit tags

Thank you so much!  That took care of it for me!