in reply to Re: Button Send
in thread Button Send

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

Replies are listed 'Best First'.
Re^3: Button Send
by VSarkiss (Monsignor) on Aug 11, 2004 at 19:27 UTC

    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.

      I'm still a little lost. That tutorial didn't really help, except to clean up my html. But I still have the problem of how to get both to work at the same time.

      Here is what I am doing:

      # Setup up # Variables # and define work fields if (-e $datefile) { open (BOBIN, ">>$datefile") || die "Cannot Open File $datefile for + writing: $!"; # Open Data file } else { ### Open directory where files data files are located # Sort in descending order, pick out first file # And e-mail it } open (BOBIN, ">$datefile") || die "Cannot create File $datefile f +or writing: $!"; } if (!(param())) { # Do stuff # By processing data # put up web page # with formatted data <form> <center><input type=submit value=Send name=S1> </center></form> } else { if (param('S1') eq "Send") { print BOBIN $datajoin; use CGI; print redirect("http://www.gailborden.info/services/b +ob/submitq.htm");} } close(BOBIN);
      I keep getting an error that it cannot open the file

      Is there easier way to just redirect it to a confirmation page AND write the data after pressing a button?

      Does anyone know, if I change the "input type" to button can I do the same thing? When clicked, redirect to confirmation page and then write the data.

      I will be more then happy to send the full script and web form.

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