/    Sign up×
Community /Pin to ProfileBookmark

cgi script – for sending a form

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

to post a comment
HTML

9 Comments(s)

Copy linkTweet thisAlerts:
@PeOfEoMar 27.2003 — 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?
Copy linkTweet thisAlerts:
@chriscam19authorMar 27.2003 — 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!
Copy linkTweet thisAlerts:
@PeOfEoMar 27.2003 — I dont use perl/cgi myself but I can give you the html part of it, do you need that? Or just the perl.
Copy linkTweet thisAlerts:
@chriscam19authorMar 28.2003 — 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.
Copy linkTweet thisAlerts:
@McGruffMar 28.2003 — 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.
Copy linkTweet thisAlerts:
@gokouMar 28.2003 — 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'}nn";
print MESSAGE "The user wrote:nn";
print MESSAGE "$FORM{feedback}n";
close (MESSAGE);

&thank_you;

}




#The following creates the Thank You page display

sub thank_you {

print "Content-type: text/htmlnn";
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);

}
Copy linkTweet thisAlerts:
@ichiro829Mar 28.2003 — hey gokou, do you have aim or icq i could chat with you about this? i need some help with this thing too.. thanks
Copy linkTweet thisAlerts:
@jeffmottMar 28.2003 — [i]gokou[/i]

[b]# 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;

}[/b]
[/quote]

This form parser is incorrect/incomplete and does not validate under strict and warnings.
[size=2]use CGI qw{param};
# now parameters are retrieved with param('name')
# rather than $FORM{name}[/size]

[b]if ($ENV{'REQUEST_METHOD'} eq 'POST')[/b][/quote]This test is now unecessary.
Copy linkTweet thisAlerts:
@Aronya1Mar 28.2003 — If you don't care what method you use, try this. Just add this code inside your <form> tag:

action="mailto:[email protected]" 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
×

Success!

Help @chriscam19 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...