Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

submit buttons

Options
  • 05-09-2002 12:42pm
    #1
    Registered Users Posts: 1,176 ✭✭✭


    I want to make a form with 2 different submit buttons, view and description. The form will call a perl script, can i determine within the perl script with button was pressed.

    I really want to do is if it is possible to have 2 submit buttons for the one form. if so i can lookup how to do it in perl etc.

    any help appreciated.


Comments

  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    The html looks something like the following where the Submit buttons have a name and value specified ...
    <form method="POST" action="envtest.cgi">
    <input type="text" name="test_text"><br>
    <input type="submit" value="sub1" name="test_sub1">
    <input type="submit" value="sub2" name="test_sub1">
    </form>


    The perl is something like ..
    my( %params ); # global place holder for key/value pair in request
    sub setParams {
    my( @pairs );
    if( $ENV{'REQUEST_METHOD'} eq 'GET' ) { @pairs = split(/&/, $ENV{'QUERY_STRING'}); }
    elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    @pairs = split(/&/, $buffer);
    }
    foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $params{$name} = $value;
    }
    }


    .. or whatever method you read the request. Using the above if one of the submit buttons was pressed $params{'test_sub1'} will hold the value of the button pressed (e.q. "sub1").

    hth
    .cg


  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    yuch, sorry about the code layout .. also beware it doesn't check for things it should so shouldn't be used on a live site.

    .cg


  • Closed Accounts Posts: 154 ✭✭mofu


    I never knew perl was so s****. How tell hell do you understand that s****? PHP and asp are so much simpler!


  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    it may look complex at first .. but once you get into it its fine, honest!! That code is just from a template I use , there are Perl modules that do this stuff behind the scense for you thus hiding the scary look!


  • Closed Accounts Posts: 154 ✭✭mofu


    okay, fair enogh...


  • Advertisement
  • Registered Users Posts: 1,176 ✭✭✭podgeen


    I'm using the perl CGI module so the code aint as tricky..
    I've got another question now, i want my script to open its outputted html in a new window... is this possible>?


  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    You could try the "Window-target" HTTP header (http://wp.netscape.com/eng/mozilla/2.0/relnotes/demo/target.htm), but not sure how browser-compatible that is.

    You could try javascript
    1) onSubmit handler opens a new window writes a form with the elements based on the current window/form) and does a form.submit in that new window
    2) when the perl gets the post, just redraw the page as it was (with the values posted too) and then use JS to popup the new window with the content or URL you want.

    .cg


Advertisement