Help needed with form submits and Perl handling

Discussion in 'Perl' started by Robert V, Jul 18, 2003.

  1. Robert V

    Robert V Guest

    Hi all, I could use some help programming on of my Perl script to handle
    different submit buttons within the same form. Here is what I have so far.

    A user goes to a Web form and inputs some data into a textarea box. Below
    this box there are two buttons ... one that is labelled "Save & Exit" and
    other that is labelled "Save and Preview" On submit of either button, the
    form data is sent to the same perl script. What I need to have happen is
    have the script detect which button was pressed and that the needed action.
    If the Save and Exit button was pressed, the script would write the data to
    my database then exit using the Print Location command ... if the Save and
    Preview button was pressed, the script would write the data to my database
    then display it. What coding would I need at the top of the script that
    would somehow determine what button was pressed, and in turn, take the
    correct action. If you can help, please add some code examples. Thankx!

    RV
    Robert V, Jul 18, 2003
    #1
    1. Advertising

  2. Robert,

    I don't know if this is a good approach, but have you tried something like:

    sample.cgi

    #!c:\perl\bin\perl
    use CGI;

    my $q = CGI::new;

    my $button1 = $q->param('myButton');

    print $q->header,$q->start_html;

    if ($button1 =~ /Preview/) {
    <--- Save and preview code --->
    }

    elsif ($button1 =~ /Exit/) {
    <--- Save and Exit code --->
    }

    <form method="POST" action="sample.cgi>
    .........
    .........
    <input name="myButton" type="submit" value="Save and Preview" />
    <input name="myButton" type="submit" value="Save and Exit" />
    </form>

    Hope that helps,
    Jeremy Fluhmann
    McLane Information Systems
    Jeremy Fluhmann, Jul 21, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Scott M.

    Run JavaScript before Form Submits

    Scott M., Nov 17, 2003, in forum: ASP .Net
    Replies:
    14
    Views:
    7,060
    Joe Gass
    Nov 18, 2003
  2. Stan
    Replies:
    1
    Views:
    2,517
    Jacob Yang [MSFT]
    Dec 3, 2003
  3. Mad Scientist Jr
    Replies:
    1
    Views:
    533
    bruce barker
    Mar 5, 2004
  4. Wysiwyg
    Replies:
    2
    Views:
    1,746
    Wysiwyg
    Apr 26, 2005
  5. Ken Adams
    Replies:
    4
    Views:
    9,469
    Sagar@1
    Jan 22, 2013
Loading...

Share This Page