From: Brian Candler Date: 2008-10-23T19:25:00+09:00 Subject: Re: using buttons in CGI Asaf Asaf wrote: > I read on the 'programming Ruby' that the submit button will update the > name of the fprm that appear on the form parameters : > for ex. @cgi.form("get","abcdc.rb") > will update the abcdc.rb form and will show this form, with no option > for me to change it. But first you need to look at what cgi.params contains; the documentation for @cgi.submit, and look at what HTML it creates; and at the w3 documentation for , which explicitly states that a form can have multiple submit buttons with different values. I find it's always wise not to trust my understanding of what I've read until I've demonstrated for myself whether it works in the way I thought it did. > so can you please explain to me how can I get the data back and how can > I handle it. Here is a fully-working example. #!/usr/local/bin/ruby -w require 'cgi' def show_form(cgi, rows) cgi.form do content = "" # content << cgi.params.inspect rows.each do |row| content << cgi.text_field("row", row) content << cgi.br end content << cgi.submit("new row", "submit") content << cgi.br content << cgi.submit("go", "submit") content end end cgi = CGI.new("html4") rows = cgi.params["row"] case cgi.params["submit"].first when "go" cgi.out do CGI.escapeHTML("You submitted #{rows.inspect}") end when "new row" cgi.out do show_form(cgi, rows + [""]) end else cgi.out do show_form(cgi, rows) end end -- Posted via http://www.ruby-forum.com/.