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

Hi,

I'm working on a script where I create a webpage with a Send button on the bottom. If the users click on it, I want to run a subroutine to write data to a file, and then give confirmation page that data was sent.

This is what I have:

print "<hr>"; print "<form>";<br> print "<center><input type=button value=Send name=S1 onclick=sendq>"; print "</center></form>"; print "</font></body></html>"; sub sendq { #print BOBIN $datajoin; use CGI; print redirect("http://www.gailborden.info/services/bob/s +ubmitq.htm"); }
Joseph A. Ruffino
Automated Systems Assistant
Gail Borden Public Library District
270 N. Grove Ave
Elgin, Il, 60120
847-742-2411 x5986

Replies are listed 'Best First'.
Re: Button Send
by VSarkiss (Monsignor) on Aug 10, 2004 at 21:39 UTC

    Using the fabulous ESP::Crystal::Ball module, I think I see the problem.

    You're expecting the onclick=sendq attribute on your <input> to call your sendq subroutine. However, an onclick handler calls Javascript, not Perl. The JS runs on the client, and Perl runs on the server. You can't connect the two like that.

    I could give you an alternative, but since I'm not sure I've diagnosed the problem, I'm going to stop here. ;-)

      Ok, Maybe I should explain my intention on this.

      I want to put a button on the bottom of my created web page, and if the user likes what he/she sees, then they will click on the send button and the data will be written to a file. Else they can quit, or go back and fix the data

      My first try, netted no results, I was trying ascertain if the button was clicked by using a simple if:

      print "<center><input type=button value=Send name=S1>"; if (S1 eq "Send") { 'send data'}
      If anyne has suggestion, I will be more than happy to learn 'em.

      Joseph A. Ruffino
      Automated Systems Assistant
      Gail Borden Public Library District
      270 N. Grove Ave
      Elgin, Il, 60120
      847-742-2411 x5986

        It sounds like you haven't written a lot of CGI programs before. You need to realize that clicking the button will do a HTTP POST against some page (often the originating one). A simple and common pattern is something like:

        use CGI qw(:standard); # easiest and safest way to do this # ... if (param()) { # Parameters were passed in: like button clicks, # text box contents, radio selections, etc. # Do something here like # if (param('S1') eq 'Send') { ... } } else { # Write HTML to produce the "baseline page" # Like # print "<input ...>" }
        There's some excellent material in the Tutorials that can help, and Ovid has a very nice online course.

Re: Button Send
by Joost (Canon) on Aug 10, 2004 at 20:46 UTC