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.
- Get the parameters that have been submitted via HTTP.
- If the parameter set is blank, read the state in from the file. (using the method you're using)
- If the parameter set came from a form submission and not from the file, save the current set of parameters to the file.
- 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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.