venganesan has asked for the wisdom of the Perl Monks concerning the following question:

I have a html table that has 2 radio buttons for every row and a save button. I want to store the value of the radio button when saved and preset the value when the page is revisited.This is the html code I have written

<form action='table_extract.pl' method = 'get'> <td><input type='radio' name='signoff' value = 'approve'>Appro +ve<br> <input type='radio' name='signoff' value='review'>Review</td> <td><input type='button' type='submit' value='Save'/></td></form>

This is what is in table_extract.pl

#!/usr/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use Fcntl qw(:flock :seek); my $outfile = "poll.out"; if (param('signoff')) { open(OUT, ">>$outfile") or die("outfile issue"); flock(OUT, LOCK_EX); seek(OUT, 0, SEEK_END); print OUT param('signoff'),"\n"; close(OUT); }else{die ("param issue");}

This is just first part of the problem. I was not able to find any output in console or in poll.out. Once I read the values, I need to preset the values to the radio buttons that was saved by the user in the previous visit.

Replies are listed 'Best First'.
Re: storing radio button value and presetting after refresh
by Corion (Patriarch) on Jul 30, 2013 at 18:26 UTC

    Have you thought about what will happen if more than one user visits your application at the same time?

    CGI::Session handles most of this for you already.

      I will look into that as well. Thanks for bringing that up. I am learning perl on the go and all suggestions help me. please suggest any changes that I need to do on the code.
Re: storing radio button value and presetting after refresh
by marinersk (Priest) on Jul 30, 2013 at 22:01 UTC
    Summary of Problem: Your HTML form has some errors in it.

    I changed your single quotes to double quotes (do not know if that is necessary) and fixed the error where you use the TYPE keyword twice in the same INPUT tag:

    <input type='button' type='submit' value='Save'/>
    Changed it to:
    <input type="submit" name="button" value="Save">
    And then I got the following output:
    Parameter count: 2 'signoff' => 'review' 'button' => 'Save'

    From this script:

    #!/user/bin/perl use strict; use CGI; &httpHeader(); &weblog(); &httpFooter(); exit; sub httpHeader { print "Content-Type: text/html\n\n"; print "<HTML>\n"; print "<TITLE>Parameter Confirmation</TITLE>\n"; print "<BODY>\n"; } sub httpFooter { print "</BODY>\n"; print "</HTML>\n"; } sub weblog { my $cgihan = CGI::new(); my @frmprm = $cgihan->param; my $prmcnt = @frmprm; #----------------------------------------- # Debugging aid #----------------------------------------- print "<P>Parameter count: $prmcnt\n"; foreach my $frmprm (@frmprm) { my $prmval = $cgihan->param($frmprm); print "<BR>\&nbsp;\&nbsp;\&nbsp;\&nbsp;'$frmprm' => '$prmval'\ +n"; } #----------------------------------------- print "</P>\n"; return; } __END__

    Perhaps this will help you get to the next stage in your experimentation?

      thank you so much for taking the effort and clearing out the mistakes. I have found out my error by searching through the forum and others. there is some issue with the form action tag in my html. It does not send the data to the .cgi script. Is there any modifications that i need to do to make it work? I did go through answers that said look into the httpd.conf file, and move the cgi file to cgi-bin folder. I tried them but to no avail. Also I do not have root access. So can you help me out along those lines?
        It works for me if you fix the submit button:
        <input type='button' type='submit' value='Save'/> # change to <input type='submit' value='Save'/>
        There is no short answer to the issue of where the CGI script needs to go and how to reference it from the HTML form.

        Usually this information is available from your web hosting provider.

        If you are not using a web hosting provider in the vulgar sense, but using, say, some system at work, check with your system administrator for the following:

        • Where the CGI directory is located
        • How to get a CGI script into the CGI directory
        • How to set permissions on the CGI script so it will execute when referenced by an HTML page
        • What is the qualified path to that directory from the web site you are using (in other words, how do you specify the value for the ACTION parameter)

        Good luck -- you are very close to getting stage one complete (reading the form).

        If I am reading your intentions correctly, you will have new challenges to overcome for the part where you'd like to preserve the state for the next page hit -- but one thing at a time. :-)