in reply to Re: Re: Saving and storing form params with cgi.pm
in thread Saving and storing form params with cgi.pm

OK, I'm assuming that what you want this script to do is maintain state in between invocations, and to allow users to change that state by submitting the form. Your code isn't (yet) able to do that. There are a couple of things that aren't clear to me, such as how exactly you expect this script to be accessed (can users stay on the form and keep resubmitting? I take it that's what you want to allow). But here's how I'd do the basic state-maintenance thing; note there's no code, because, as bjelli points out, the problem all along was with your program logic, which tells me that's what you need to think about first here.
  1. Get the parameters that have been submitted via HTTP.
  2. If the parameter set is blank, read the state in from the file. (using the method you're using)
  3. If the parameter set came from a form submission and not from the file, save the current set of parameters to the file.
  4. Present the form, with each field containing the relevant value from the parameter set that we have.

If that's not what you wanted to do, then you'll need to be more explicit.

The idea here is that when users come to your CGI for the first time, they'll receive the saved state. If they then submit the form, what they submit will get saved to the file.

HTH

  • Comment on Re: Re: Re: Saving and storing form params with cgi.pm