Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

form buttons

by win95progman (Initiate)
on Nov 30, 2001 at 14:59 UTC ( #128594=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I have a form with three submit buttons on it. Can someone tell me how to tell which button was pressed within my script? Thanks in advance, Tom.

Replies are listed 'Best First'.
Re: form buttons
by stefan k (Curate) on Nov 30, 2001 at 15:09 UTC
    Usually you give your submit button a value and a name:
    <input type="submit" name="action" value="Search"> <input type="submit" name="action" value="Logout">
    and if you
    use CGI;
    you can then test for what action to do:
    if (param("action") eq "Search") { # ... } # ...

    Please take into account that this comes from the back of my head and I have not been doing CGIs for more than a year now; still it should be correct.

    Regards... Stefan
    you begin bashing the string with a +42 regexp of confusion

Re: form buttons
by Anonymous Monk on Nov 30, 2001 at 15:12 UTC
    Give all the buttons the same name but different values.
    <input type="submit" name="action" value="button1"> <input type="submit" name="action" value="button2"> <input type="submit" name="action" value="button3">
    Then in your CGI the action parameter will be 'button1' or 'button2' or 'button3' depending on which is pressed.
    my $query = CGI::new(); #assign value to $action my $action = $query->param('action');
    you can then say
    if ($action eq 'button1') { #do your thing }elsif ($action eq 'button2'){ #do another thing }
Re: form buttons
by kwoff (Friar) on Nov 30, 2001 at 20:09 UTC
    Also, sometimes you want to separate the buttons in different <FORM> sections.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://128594]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2022-07-05 18:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?