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

Hello All!

My question will catogorize me as the extreme newbie I am, but I humbly request some help. I have spent about 4 hours searching the archives here before asking.

I have this little script that writes data from a text file to an HTML page on pressing "submit" and it works great. However, I would like to add a little subroutine that acknowledges the action was accomplished. I have tried to understand setting a value in a hidden field and using that to branch to a little "print" sub, but I guess I have not the understanding yet how to do this.

Would any kind soul give me an example how to use "Submit" to not only do its thing, but to also set a flag that will branch to a little "print" subroutine after Submit has been pressed? Thanks so much for helping if you will.

Replies are listed 'Best First'.
Re: Run a subroutine on "Submit"
by tachyon (Chancellor) on Nov 13, 2002 at 10:11 UTC

    Here is the basic structure you want.

    #!/usr/bin/perl -w use strict; use CGI; my $q = new CGI; my $flag = $q->param('flag'); my $message = get_data(); display_page($message); # do mysub() if 'flag' set mysub() if $flag eq 'do_it'; exit; #### Subs #### sub display_page { my $message = shift; print $q->header, $message; } sub mysub {} sub get_data { }

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Thank you so much! Just what I was looking for. Many blessings for your help!

        There was a typo in the original if $flag = 'do_it' should of course have been if $flag eq 'do_it'

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Run a subroutine on "Submit"
by Chady (Priest) on Nov 13, 2002 at 07:55 UTC

    based on your question, the answer would be: "set a flag while submitting to branch a little print subroutine."

    a more elaborate answer would require you to show us a bit of the code you are working on. and in fact, by writing the text file to the html page, it means that you already got your flag, right? so this is probably where to insert the sub. But that's all guessing until we see the code.


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/