On Wednesday 22 January 2003 01:39 am, Vandemoortele Simon wrote:
> I am entirely new to CGI scripting and trying to make an interface to
> edit my dynamic photo-album (add sections, pictures, etc). I've
> discovered in the process how inefficient it can be to code a UI with
> ! since every time you need more input from the user you have
> to send him to another (or the same) script and doing so *lose all the
> input you have collected*.
> Until now I've been solving that problem by sending all the collected
> input along as 'hidden params' but that's a lot of work.
> Is there a better way ? Would that be CGI::Session ?
> or CGI::Session::PStore ?

Simon, there is a better way.

you can actually marshal an entire Ruby object via a single html hidden 
parameter. this is what i have done with Jigsaw (my web app framwork). jigsaw 
is not yet ready for public consumption (although it is gettting close). but 
here is the basic idea:

  def marshal_to_html(name, iobj)
    data = CGI.escape(Marshal.dump(iobj))
    print(%Q{<input type="hidden" name="__#{name}__" value="#{data}"/>\n})
  end

  def marshal_from_html(name)
    return Marshal.load(CGI.unescape(self["__#{name}__"][0])) if \
	self.params.has_key?("__#{name}__")
  end

with Jigsaw i have added these two methods directly to the CGI class itself.

thus if you keep all the data you collect from a user within a sinlge object 
you can simply marshal that object from page to page.

-- 
tom sawyer, aka transami
transami / transami.net


                                   .''.
       .''.      .        *''*    :_\/_:     .
      :_\/_:   _\(/_  .:.*_\/_*   : /\ :  .'.:.'.
  .''.: /\ :   ./)\   ':'* /\ * :  '..'.  -=:o:=-
 :_\/_:'.:::.  | ' *''*    * '.\'/.' _\(/_'.':'.'
 : /\ : :::::  =  *_\/_*     -= ;) =-  /)\    '  *
  '..'  ':::' === * /\ *     .'/.\'.   '._____
      *        |   *..*         :       |.   |' .---"|
        *      |     _           .--'|  ||   | _|    |
        *      |  .-'|       __  |   |  |    ||      |
     .-----.   |  |' |  ||  |  | |   |  |    ||      |
 ___'       ' /"\ |  '-."".    '-'   '-.'    '`      |_.
------------------------------------------------------------