Click to See Complete Forum and Search --> : cgi script - for sending a form
chriscam19
03-27-2003, 03:51 PM
I need to make a form and have people fill out information then click submit and then it be emailed to me. I heard its best to use a cgi script. can someone walk me through it? Please tell me where to get the cgi script and how to put it in my html form.
thanks
chris
PeOfEo
03-27-2003, 04:59 PM
Who told you cgi? It can be done with any server side language and depending on ur mail provider it can be done client side too. First thing you need to do is see what your host supports. Who is your host?
chriscam19
03-27-2003, 05:08 PM
I am with earthlink.net. it supports cgi. I have a cgi-bin folder on my server. See different people are going to be accessing my this form from different computers. I just heard cgi scripts work better but I dont care as long as it works and when the information gets email to me it is clear and organized!
PeOfEo
03-27-2003, 05:11 PM
I dont use perl/cgi myself but I can give you the html part of it, do you need that? Or just the perl.
chriscam19
03-27-2003, 06:01 PM
um, I dont know which part I need. all I have is the form that goes into the html. I know nothing else so you would have to walk me through it please.
McGruff
03-27-2003, 07:11 PM
php (php.net) would be my first choice if you want to write your own server-side stuff.
Or, you might find a ready-made perl script to slot into your cgi bin on hotscripts.com.
gokou
03-27-2003, 11:11 PM
Heres a cgi form script.
Place this script in your cgi-bin directory. In your html form, you will need to write the following code.
<form method="post" action="location of cgi script">
<INPUT TYPE="hidden" NAME="submitaddress" VALUE="your email">
#!/usr/bin/perl
# That is the path to PERL just above It MUST be first in the script
# The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# The following sends the email
open (MESSAGE,"| /usr/lib/sendmail -t");
print MESSAGE "To: $FORM{submitaddress}\n";
print MESSAGE "From: $FORM{name}\n";
print MESSAGE "Reply-To: $FORM{email}\n";
print MESSAGE "Subject: $FORM{selection} $ENV{'REMOTE_HOST'}\n\n";
print MESSAGE "The user wrote:\n\n";
print MESSAGE "$FORM{feedback}\n";
close (MESSAGE);
&thank_you;
}
#The following creates the Thank You page display
sub thank_you {
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD>\n";
print "<TITLE>Thank You!</TITLE>\n";
print "</HEAD>\n";
print "<BODY BGCOLOR=#FFFFCC TEXT=#000000>\n";
print "<H1>Thank You!</H1>\n";
print "\n";
print "<P>\n";
print "<H3>Your $FORM{selection} is greatly appreciated.<BR>\n";
print "<P>\n";
print "<h3>You wrote: $FORM{feedback}.<br>\n";
print "</BODY>\n";
print "</HTML>\n";
exit(0);
}
ichiro829
03-28-2003, 04:52 PM
hey gokou, do you have aim or icq i could chat with you about this? i need some help with this thing too.. thanks
jeffmott
03-28-2003, 05:04 PM
gokou
# The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
This form parser is incorrect/incomplete and does not validate under strict and warnings.
use CGI qw{param};
# now parameters are retrieved with param('name')
# rather than $FORM{name}
if ($ENV{'REQUEST_METHOD'} eq 'POST')This test is now unecessary.
Aronya1
03-28-2003, 05:18 PM
If you don't care what method you use, try this. Just add this code inside your <form> tag:
action="mailto:youremailaddress@yourdomain.com" method="POST" enctype="text/plain" name="formnamegoeshere"
You might want to add a notice to the user not to click "Submit" more than once, or they might send you form results numerous times.
No point in making things complicated if it isn't neccessary.
Aronya1