Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl remember html checked box or radio button?? 2

Status
Not open for further replies.

noshankus

Programmer
Mar 31, 2003
3
DE
Hello,

I am relatively new to this, so I'm not even sure if this is the easiest way to go about this problem.

I have a couple of check boxes written in html stored in a Perl file that is run through cgi.

The problem is that I want to be able to dissable the checked boxes after they have been submitted - only for that day!

i.e. The user goes to the site, ticks a few boxes, submits it. A second user comes along, and can't tick the boxes that have already been ticked by the previous user.

I thought this might be possible, as Perl is server side.

Thank you as always for the help and hints :)
Best regards,
 
Maybe you could have some sort of server side file, that your perl code looks for. Even an empty file with a name like 033103 (The date). All you would have to do is use an if statement that checks for the existence of the file and then does or does not do something according to that.

If you need help with the actual code, I can help, but from the sound of it, you could probably do the coding, but your just looking for ideas...
 
Hi.

CGI is confusing at first, but bear with it. I've tried several languages and perl is certainly the easiest for this sort of project.

What you wish to do is perfectly possible. What you need is data persistance between invocations and you'll only get that with some sort of back-end "database" - even if it's only a file. If it is a file, however, you'll have record locking problems so it may be easier to use a database if you have one handy and/or are familiar with such things.

The strategy would be to have your cgi script read the database to get the current state and use this to influence the page generated. In crude pseudo-code:
Code:
my @things = qw{ big blue yellow juicy };

if ( param('submit') ) {
    foreach my $thing (@things) {
        write_to_database($thing) if param($thing);
    }
    print header, start_html, h1('Got that!'), end_html;
} else {
    print header, start_html, h1($Title), start_form;
    foreach my $thing (@things) {
        my $already_or_not = get_from_database( $thing );
        print $already_or_not ?
           'sorry - someone's already selected this $thing!', br
        :
            checkbox( -name=>$thing ), br;
    }
}
print submit, end_form, end_html;

This clearly omits the details of your database interaction but that is going to depend to a huge extent on your circumstances.

Good luck, "As soon as we started programming, we found to our surprise that it wasn't as
easy to get programs right as we had thought. Debugging had to be discovered.
I can remember the exact instant when I realized that a large part of my life
from then on was going to be spent in finding mistakes in my own programs."
--Maurice Wilk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top