From: David Alan Black Date: 2001-11-16T08:01:52+09:00 Subject: [ruby-talk:25355] Re: CGI beginner's trouble Hello -- On Fri, 16 Nov 2001, Niklas Backlund wrote: > require 'cgi' > > cgi = CGI.new("html3") > > cgi.out { > cgi.html { > cgi.head{ cgi.title{"Submit news..."} } + > cgi.body{ "\n" + > cgi.form{ "\n" + > cgi.textarea("get_text") + "\n" + > cgi.br + > cgi.submit("Submit") > } > } > } > } > if cgi["get_text"] != nil > print "Previous result: " + cgi["get_text"].to_s > end > > > It works as I expected to: I enter some text, hit 'Submit' and I get the > same page again, this time with the result printed below the form (just > for testing). That result shouldn't actually show up, since it's after the closing tag, but I guess your browser isn't picky :-) > But I want to save the text I entered to a text file (or whatever) and > send back some confirmation text -- I don't want the form to appear > again. If I try to acheive this with some test ( if cgi["get_text"] == > nil cgi.out{...} ) I will get stuck in the "presentation mode", because > when trying to reload the page, I have to repost the form data, which > will prevent me from getting the form back again... How do I make it > "forget" my previous entry? You should be able to branch on whether or not there's a get_text: require 'cgi' cgi = CGI.new("html3") cgi.out { if cgi["get_text"] cgi.html { cgi.head { cgi.title{"Result"} } + cgi.body { "Form result: " + cgi["get_text"].to_s } } else cgi.html { cgi.head{ cgi.title{"Submit news..."} } + cgi.body{ "\n" + cgi.form{ "\n" + cgi.textarea("get_text") + "\n" + cgi.br + cgi.submit("Submit") } } } end } David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav