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

Dear Monks,

I have call the html file in cgi. In html file, there are three buttons view, edit and delete. If i click the view button it has to go to seperate cgi file and if i click edit button it has to go to seperate cgi file viceversa. Without using javascript in my project i have to do. so, please help me how to write the cgi code.

Thanks in advance

Replies are listed 'Best First'.
Re: CGI and HTML form
by davidrw (Prior) on Jun 14, 2005 at 02:25 UTC
    Instead of javascript, you could just put the buttons in separate <form> tags so they have different actions. (Why no javascript?)
    <form action="prog1.cgi"> ... <input type="submit" value="View"> </form> <hr> <form action="prog2.cgi"> ... <input type="submit" value="Edit"> </form>

    If you want to do it strictly on the backend, a couple thoughts come to mind. First is that the script you submit to simply looks at the button value and then does a redirect to the appropriate .cgi url (constructing a query string of course so values are preserved). Take a look at CGI, specificall the param() and redirect methods.

    Second backend way (and probably better) is that you just have one cgi file, but it (depending on the button value) calls code from different files (different "include" files or modules). Take a look in the Tutorials section for basics on modules and Including files.
    my $btn = $q->param('button'); if( $btn eq 'viewBtn' ){ ... }elsif( $btn eq 'editBtn' ){ ... }else{ ... }
      re "why no js?" -- accessibility issues: NYS website rules, for example, effectively make use of .js a non_starter, as rules require that sites must provide users of lynx (or other non-js website visitor) an "equivalent experience" which (in part because of other parameters) translates to "maintain a parallel, text_only site;" do all (potentially js) work on the server-side; or violate the rule.
Re: CGI and HTML form
by nedals (Deacon) on Jun 14, 2005 at 02:56 UTC

    Concuring with davidrw, combining the scripts into one is probably the easiest method.

    If, however, you need to keep seperate scripts, take a look at LWP::UserAgent