hi, I am using form_processor.pl as my cgi script. The script has 5 options. I have email admin turned on and the other four options turned off. Maybe the problem is in my html code. my html code is:
<form action="http://www.url.com/cgi-bin/form_processor.pl" method="post">
<div align="center">
<p> <font size="1" face="Arial, Helvetica, sans-serif">Name</font>
<input type="TEXT" name="01)user_name"> <br>
<font face="Arial, Helvetica, sans-serif"> <font size="1">Email</font>
<input type="TEXT" name="02)required_name"> <br>
<input type="submit" value="Get my invitation now!">
</font>
<input type="hidden" name="admin" value="email address.com">
<input type="hidden" name="subject" value="send my invitation">
<input type="hidden" name="redirect" value="http://www.url.htm">
<br>
</p>
</div>
</form>
cgi script
Client Customization Variables
#Option No. 1
$email_admin = 1; #1 is on; 0 if off;
#Option No. 2
$write_form_info = 0; #1 is on; 0 is off;
#Path of file to write form data to. Must be read/writeable
$form_info_path = "/txt/txt.txt";
#Option No. 3
$email_datafile = 0; #1 is on; 0 is off;
#Path to email addresses datafile
$email_datafile_path = "/usr/local/etc/httpd/htdocs/demos/feedback_emails.txt";
#Option No. 4
$send_email_to_user = 0; #1 is on; 0 is off;
#Path of text file to be sent to user
$feedback_response_path = "/usr/local/etc/httpd/htdocs/demos/feedback_response.txt";
#Option No. 5
$include_field_name = 0; #1 is on; 0 if off;
#Subject of email sent to user
$email_subject = "Thank you for signing up";
#Path to sendmail
$mailprog = "/usr/sbin/sendmail -t";
$date_command = "/bin/date";
#You should not need to change anything beyond this point
$date = $date_command +"%D";
#Go through the required fields and send to user an error message if field is empty
while (($key, $value) = each %input) {
if ($key =~ /required-/ && $value eq "") {
$key =~ s/\d)required-*//g;
print &PrintHeader;
print "The $key field is required. Please use the back button on your browser to ";
print "enter the required information and submit the form again. Thank you.";
exit;
}
}
#Take all the fields that begin with a number, sort them by number and put them into #the sortedkeys array
foreach $key (sort(keys(%input))) {
if ($key =~ /user_email/) {
$user_email = "$input{$key}";
$user_email =~ s/\d)\s//;
$user_email =~ s/required-//;
}
unless ($key =~ /\d+/) {
next;
}
push (@sortedkeys, "$key|$input{$key}");
}
#Send email to admin if selected
if ($email_admin == 1) {
&email_admin;
}
#Send text file to user if selected
if ($send_email_to_user == 1) {
&send_info;
}
#Write form data to file if selected
if ($write_form_info == 1) {
&write_form_info;
}
#Write email addresses to datafile if selected
if ($email_datafile == 1) {
&write_email_datafile;
}
sub write_email_datafile {
open (EMAIL, ">>$email_datafile_path") || die ("I am sorry, but I was unable to open the file $email_datafile_path");
print EMAIL "$user_email\n";
}
sub write_form_info {
open (FORM, ">>$form_info_path") || die ("I am sorry, but I was unable to open the file $form_info_path");
foreach $sortedkeys (@sortedkeys) {
$sortedkeys =~ s/\d)\s//;
$sortedkeys =~ s/required-//;
($name, $answer) = split (/|/, $sortedkeys);
print FORM "$name -- $answer\n";
}
print FORM "\n";
close (FORM);
read me text
General Instructions
###
Install form_processor.pl in your cgi-bin and chmod to 755. Install cgi-lib.pl in your cgi-bin and chmod to 755.
The html form you design must include the following fields:
<input type="hidden" name="admin" value="your_email@your_server.com">
<input type=hidden name="subject" value="Subject of Email to Yourself">
<input type=hidden name="redirect" value=
"http://www.page_shown_after_submit.com">
The form action must point to the location of the script on your server.
<form action="/cgi-bin/form_processor.pl" method="POST">
In additon, if you are using Option No. 4, the field that gets the users email address MUST be named user_email.
<input type="TEXT" name="02)user_email">
(any digits may be used, purpose of digits is explained below)
When designing the html form, all fields that you want input from must begin with a digit and a right parenthesis i.e. <input type="TEXT" name="01)name" value="Kendall">. The digit serves to order the fields in the results you receive.
For instance;
<input type="TEXT" name="01)name" value="Kendall">
<input type="TEXT" name="02)email" value="kendall@command-o.com">
Returns:
name -- Kendall
email -- kendall@command-o.com
Whereas;
<input type="TEXT" name="02)name" value="Kendall">
<input type="TEXT" name="01)email" value="kendall@command-o.com">
Returns:
email -- kendall@command-o.com
name -- Kendall
Keep in mind that the name of the field (minus the digits and parenthesis) will be used as the description of the field in the results you receive.
If you want a field to be required, use the following:
<input type="TEXT" name="01)required-name" value="Kendall">.
This will give the user a message that he needs to fill in the "name" field to continue. This example will produce the following result:
name -- Kendall
###
Options
###
1. To have the results of the form emailed to you, the script variable $email_admin must be set to 1.
$email_admin = 1;
If you do not want the results emailed to you, set this to 0.
- To have the results of the form written to a text file, the script variable $write_form_info must be set to 1.
$write_form_info = 1;
If you do not want the results written to a text file, set this to 0.
If this option is set to 1, you must include the system path to the file you want the results written to in the variable $form_info_path. This file must have write permissions.
- To have the email addresses of the users written to a text file (mailing list), the script variable $email_datafile must be set to 1.
$email_datafile = 1;
If you do not want the email addresses written to a text file, set this to 0.
If this option is set to 1, you must include the system path to the file you want the results written to in the variable $email_datafile_path. This file must have write permissions.
- To use the option of sending a text file via email to the user after the form has been
filled out, the script variable $send_email_to_user must be set to 1.
$send_email_to_user = 1;
If you do not want to email a text file, set this to 0.
If this option is set to 1, you must include the system path to the file you want to email to the user in the variable $feedback_response_path. This file must have read permissions.
- To include the field names in the results your receive, the script variable $include_field_name must be set to 1.
$include_field_name = 1;
If you do not want the names appearing, set this to 0.
###
Other Variables to Set
###
$email_subject = "Thank you for your interest";
This is the subject of the email that is sent to the user if Option No. 4 is selected.
$mailprog = "/bin/sendmail -t";
This is the system path to your server's sendmail program.
$date_command = "/usr/bin/date";
This is the system path to your server's date command.
i can NOT figure out why I am sent duplicate messages. I have tried taking the email field out and with only one field i still get the duplicate messages. helpp....
thanks