From: Alan Chen Date: 2001-11-16T08:00:51+09:00 Subject: [ruby-talk:25354] Re: CGI beginner's trouble On Fri, Nov 16, 2001 at 07:14:22AM +0900, Niklas Backlund wrote: > Hi, > > I'm failing with CGI on such a basic level, it's almost scary! So > please, if you're sensitive, stop reading now... =) > > I've been working on a new web page using mod_ruby and eRuby for Apache. > The eRuby stuff I've done has been working perfectly, so no complaints > there! > > The thing is that I want to be able to submit data to my webpage when > I'm travelling, and I thought the easiest way to accomplish this would > be to have a "backdoor page" with a CGI form where I could enter the > text I want to submit. Later, I would include functions to preview my > entry before submitting and editing previous entries. > > However, the problems start already during the first step... Being the > novice I am, I used the examples in "Programming Ruby" as a starting > point. Here's my first primitive program: > > > 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). > > 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? > > Or did I get it all wrong somehow...? > > I was unable to try things out in 'irb' (as I usually do when I'm > experimenting) as I also get the following dilemma: > > irb(main):001:0> require 'cgi' > true > irb(main):002:0> cgi = CGI.new("html3") > (offline mode: enter name=value pairs on standard input) > > from which there seems to be no escape other than breaking out of > 'irb'... > > > /Niklas what the cgi is asking for is the cgi paramters to send. You can enter as many name=value pairs as you want and then hit Ctrl+D to send them into your cgi script. For this sort of thing, I really prefer eruby. I'm currently working on a web application so if you want help on that you can mail me and I'll help you off the list. If you want to continue to build with what you have, then I would suggest adding a hidden input which a script can set the value of to manage your state. -- Alan Chen Digikata LLC alan@digikata.com http://digikata.com