2 submit buttons in a form

前端 未结 3 970
感动是毒
感动是毒 2020-12-31 19:05

I have a question about forms. I have a fairly standard form that saves a post (called an eReport in my app) with a title and body. The table also has a \"published\" field,

3条回答
  •  旧时难觅i
    2020-12-31 19:29

    in addition to @iddlefingers answer, here is a view of the log of the application (striping some useless params due to explanation purposes)

    Parameters: {"utf8"=>"✓", ..., "comentar"=>"Confirmar"}
    

    where we can see that comentar is the name of the parameter, and "Confirmar" is it's value, which is the button's text too.

    which was obtained by submit_tag "Confirmar", :name => 'comentar'

    So in general you could have (if you want to reduce the number of params you are working with) several submit_tag "onevalue", :name => 'SAMEname', submit_tag "othervalue", :name => 'SAMEname'...

    and retrieve them in your controller

    if params[:SAMEname] == "onevalue"
    # do stuff
    elsif params[:SAMEname] == "othervalue"
    #do different stuff
    end
    

提交回复
热议问题