Forum Moderators: coopster & phranque

Message Too Old, No Replies

Setting up a basic webform.

What scripts are needed?

         

KougarLOB

8:06 am on Jul 22, 2005 (gmt 0)

10+ Year Member



I have set up the web page and I have everything set the way I want them with values and names for each category in the form along with a Thank-you page. I even have a javascript that checks to see if all the fields are filled in. The only thing that stumps me is the ACTION line. I know something goes there, but no files or scripts came with the CGI-BIN folder.

This is not my site, but I was hired on to re-design a site. I have the user name, password, and can upload/delete files. I made the mistake of suggesting a web-form so that visitors can make requests in an organized way instead of littering the site with mailto: links. I haven’t done a form in years and I know ACTION=mailto: isn't kosher anymore.

----------
My goal is to end up with a plain text e-mail with:

Name: (nametextbox)
Phone: (phonetextbox)
e-mail: (e-mailtextbox>

Menu1: (OptionchosenfromMenu1)
Menu2: (OptionchosenfromMenu2)
Menu2: (OptionchosenfromMenu2)

(Lastly, include text from the TextArea box)
(end e-mail)
----------

I have been to a number of websites that either offer free scripts or instructions on how to create your own, but I am either stumped by the vague instructions or it is referring to a file, program, or folder that is not on (or not visible) on the server. Also, every website offers completely different instructions for simple web-forms.

I guess what I saying is "What do I need?" There were no files in the CGI-Bin folder when I got the site. I do not see a folder called SendMail and my repeated attempts at asking my "boss" if these things were included when she got the domain have gone unanswered yet my deadline draws neigh. I do most of my work elbow-deep in HTML code – maybe script coding is too much for me.

SeanW

12:36 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



First you need to figure out how you'd install a CGI once you get it. If you have a CGI directory, that's probably where, and you probably access it through /cgi-bin/ in your URL.

So, if you have email.cgi in your cgi-bin directory, your form will have action="/cgi-bin/email.cgi"

It might be easier to test with a simple script just to make sure everything's running. On Unix, I usually bang up a shell script:

#!/bin/sh

echo "Content-type: text/html"
echo
echo "Hello, world!"

If I can access it as /cgi-bin/test.cgi, I'm golden. If not, I start looking at the error I get and such.

Failing all that, ask your provider how to do it. They might even have some recommended templates for scripts.

To write the script, I'd look at CGI.pm, since it handles all the processing.

Sean

lexipixel

7:29 pm on Jul 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are (3) parts;
1. an HTML form
2. a script to catch the data
3. sendmail to mail the data

I think you are missing the middle parts, a CGI script to "catch" the FORM data and send it out via sendmail.

You FORM "action" would POST to this script.

#!/usr/local/bin/perl
#
# MAILFORM.CGI
#
# set the vars below to meet your needs.
#
$MailTo = 'some.person@domain.tld';
$MailFrom = 'webmaster@domain.tld';
$subject = 'Contact Form (DOMAIN.TLD)';
$HTML_index = 'http://www.domain.tld/';
$dateCmd = '/bin/date';
$mailprog = '/usr/sbin/sendmail';
#
# Parse url for CGI pairs of parameters and values
#
if ($ENV{'QUERY_STRING'}) {
$buffer = $ENV{'QUERY_STRING'};
} elsif ($ENV{'CONTENT_LENGTH'}) {
read (STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
}
#
$txt = '';
#
@cgiPairs = split(/&/,$buffer);
foreach $cgiPair (@cgiPairs) { ($name,$value) = split(/=/,$cgiPair);
$value =~ s/\+/ /g;
$value =~ s/%(..)/pack("c",hex($1))/ge;
$txt .= "$name = $value\n";
}
#
chop ($TimeStamp = `$dateCmd +"%a %D %H:%M %Z"`);
#
open (MAIL,"¦$mailprog -t");
print MAIL "To: $MailTo\nFrom: $MailFrom\n";
print MAIL "Subject: $subject\n";
print MAIL "\n$txt\n(Sent: $TimeStamp)\n\n";
close (MAIL);
#
print "Content-Type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Form Sent</title>\n";
print "</head>\n";
print "<BODY>\n";
print "<BR>Form sent by email $timeStamp<BR><BR>\n";
print "<A HREF=\"$HTML_index\"><B>Click Here<BR>to return to<BR>Home Page</B></A><BR><BR>";
print "</BODY>\n";
print "</HTML>\n";
#
#

Hope this helps.

[edited by: jatar_k at 4:46 pm (utc) on July 25, 2005]

KougarLOB

8:18 pm on Jul 23, 2005 (gmt 0)

10+ Year Member



Thank you both. I'll give it a try.

Another two days have pasted and I still have yet to hear from her or her web-hosting company.

lexipixel

12:14 am on Jul 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Don't know if you know the script "basic"...

- upload scripts in ASCII format
- set permissions (CHMOD 755 on the script I posted)

If this doesn't get you anywhere, you'll need to start with a basic "hellow world" type of perl script for testing and then take it from there.

lexipixel

12:19 am on Jul 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




Just noticed the "" in the script I posted... the forum software here (at WebmasterWorld) put that in. It SHOULD NOT be in the script.

KougarLOB

7:11 am on Jul 24, 2005 (gmt 0)

10+ Year Member



Remove all "" marks? Okay.

lexipixel

12:52 am on Jul 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month


NO --- just take out where it say "[smile stopper]" (I had to space it out like that --- there is something in this forum software that put that in and when I tried to tell you about it it replaced the word "smile stopper" with quotes.

I check off-
"Disable graphic smile faces for this post?"
and
"Disable [codes] for this message?"

Don't know why that got inserted -- I've never seen it before.

WWMike

5:04 am on Jul 25, 2005 (gmt 0)

10+ Year Member



It's probably because you have a space between the closing parenthesis and the semicolon at the end of the open (MAIL line. That space shouldn't be there and the accented uppercase A near the beginning of the line right before the pipe character shouldn't be there either.

biggerfish

5:44 am on Jul 25, 2005 (gmt 0)

10+ Year Member



If you have PHP available on that box, you can use Felgall PHP Form to Mail Script (google that phrase to find it, can't post a link here.)

It reads any field you throw at it, doesn't require CGI access, etc. Easy to use, easy to customize the output of the email.