Solved

Print INPUT VALUE to file

Posted on 1998-06-25
8
217 Views
Last Modified: 2010-03-05
I am printing a very simple mail form to a temp file to be mailed with windmail
and need some vision on how to include the forms input value into my little file
"<INPUT TYPE=TEXT NAME="email" SIZE=25  ROWS="1">".  Essentialy,
a user will just type in their email address and then click Submit which calls the little
script below to print the submitted email address to a temp file ($email).
Also, if you could add a little snippet at the end to call a confirmation
page would be nice to.

Sample script:
------------------------------------------------------------
#perl.exe

$dir = "c:/windows/temp";
$mailprog = 'windmail.exe';
$To = "listserver\@bigfoot.com";

{
 open(MAIL,">$dir\\tempfile") || die("Cannot open $dir\\tempfile -- Check Directory Permissions : $!");

    print MAIL "From: $To\n";
    print MAIL "To: $To\n";
    print MAIL "Subject: E-mail Submission\n\n";
    print MAIL "------------------------------------------\n";
    print MAIL "Submitted Address: $email  \n";
    print MAIL "------------------------------------------\n\n";
    close (MAIL);
 
        use Win32::Process;
        use Win32;
        Win32::Process::Create($ProcessObj, $mailprog, "windmail -t -n $dir/tempfile ", 0, DETACHED_PROCESS, ".")|| die;
        $ProcessObj->Wait(0);
}
0
Comment
Question by:Biffo
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 2

Author Comment

by:Biffo
ID: 1208185
Edited text of question
0
 
LVL 4

Expert Comment

by:martinag
ID: 1208186
To get the value of email, use $ENV{'HTTP_EMAIL'}.
So this is your only change:
print MAIL "Submitted Address: $email  \n";
to
print MAIL "Submitted Address: $ENV{'HTTP_EMAIL'}  \n";

And the redirect...
Print STDOUT "Location: http://your.site.com/thanks.htm\n\n";

Martin
0
 
LVL 6

Expert Comment

by:alamo
ID: 1208187
$ENV{'HTTP_EMAIL' is not the value the user entered into the form.

Since this is a result of a forms submission, you need to do the standard translation and parsing of QUERY_STRING (if it's a GET, STDIN if it's a POST) into a hash, and then use the value of 'email' from that hash.

This is boilerplate stuff available in a lot of places (once you know what to look for), but if you want the exact code, say so and I'll post it. good luck!
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 2

Author Comment

by:Biffo
ID: 1208188
Ok alamo, post the boilerplate code for the above!
0
 
LVL 2

Accepted Solution

by:
tpryor earned 50 total points
ID: 1208189
http://cgi-lib.stanford.edu/cgi-lib/

go there for the boilerplate, it is called cgi-lib.pl
example code...

#!/usr/local/bin/perl

# $Header: /cys/people/brenner/http/docs/web/RCS/simple-form.cgi,v 1.4 1996/03/29 22:07:56 brenner Exp $
# Copyright (C) 1994 Steven E. Brenner
# This is a small demonstration script to demonstrate the use of
# the cgi-lib.pl library

require "cgi-lib.pl";

MAIN:
{

  # Read in all the variables set by the form
  &ReadParse(*input);

  # Print the header
  print &PrintHeader;
  print &HtmlTop ("cgi-lib.pl demo form output");

  # Do some processing, and print some output
  ($text = $input{'text'}) =~ s/\n/\n<BR>/g;
                                   # add <BR>'s after carriage returns
                                   # to multline input, since HTML does not
                                   # preserve line breaks

  print <<ENDOFTEXT;

You, $input{'name'}, whose favorite color is $input{'color'} are on a
quest which is $input{'quest'}, and are looking for the weight of an
$input{'swallow'} swallow.  And this is what you have to say for
yourself:<P> $text<P>

ENDOFTEXT


  # If you want, just print out a list of all of the variables.
  print "<HR>And here is a list of the variables you entered...<P>";
  print &PrintVariables(*input);

  # Close the document cleanly.
  print &HtmlBot;
}

GL
t
0
 
LVL 4

Expert Comment

by:martinag
ID: 1208190
The code I submitted works. It's easy to use if you only use one, maybe two, variables.
If the form consists of more variables, I think that one should use tpryor's splitting code.

Martin
0
 
LVL 6

Expert Comment

by:alamo
ID: 1208191
Sorry, Martin, but you are wrong - that won't work at all. You better look at it again.
0
 
LVL 4

Expert Comment

by:martinag
ID: 1208192
Well, then is my Perl-book wrong.
Apologize...

Martin
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question