Forum Moderators: mack

Message Too Old, No Replies

Need help making form work

How to make a form work

         

sunshineseeker71

9:08 am on May 15, 2008 (gmt 0)

10+ Year Member



How do you make a form work?

I can create them, that's easy enough. But, how do you get a form to work and actually submit?

I am using 1and1 for hosting. I also have a site on freewebs, which I just converted to HTML. (from the site builder).

I have only been making web pages for about a year- the first half on a site builder. So, most of what I read is greek to me.

Does every hosting account have it's own code to put into forms? Where do you find that code? Is it a different code for every person that uses the hosting account? I'm so confused.

I appologize if this question has been answered here- if so- just please direct me to the thread.

Thanks in advance!

Sunshine

[edited by: engine at 9:52 am (utc) on May 15, 2008]
[edit reason] WebmasterWorld TOS [/edit]

wheelie34

12:56 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



They usually run on formmail.pl or .cgi, all details from the form get processed by the script which then emails the contents to the email address set in the script, sent a sticky to you to 1and1 faq page

piatkow

2:07 pm on May 15, 2008 (gmt 0)

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



Its pretty common for hosting services to provide formmail.pl/.cgi these days but documentation may be negligable. There may also be restrictions on the target email address.

I learned about forms by using a free hosted service which provided a good tutorial and on-line form building software. Once I was comfortable that I understood that I switched to the formmail script provided by my web host.

rocknbil

5:58 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard sunshineseeker!

How do you make a form work?

When you press "submit," it is the browser that recognizes your form and sends that information to a server-side processor, which I will explain in a second. There are two methods for doing this. The default is "get," which will basically send a query string composed of the form data to the processor, as in

some-script.cgi?var1=1&var2=2&var3=3

The second is "post" where the data is sent as a set of key value pairs in block of data that may or may not contain multiple parts (as in file upload attachments.) The difference is, with the get method, there is a limitation on the actual amount of data that will be sent, and also it will display the (ugly) query string in the address bar.

As I said, get is default, so this
<form action="yourscript.cgi">
is equivalent to this
<form method="get" action="yourscript.cgi">

as opposed to post.
<form method="post" action="yourscript.cgi">

The server-side processor can be any executable script or program configured to accept the data from a form. In the above example, the script is "yourscript.cgi." This script can be in any language, depending what you have available: perl, PHP, ASP, ColdFusion, even a compiled executable program written in C or C++. In the above replies, formmail.pl is a perl script freely available for this purpose.

What the server side processor does is accept the data submitted by either method and starts off by breaking down the data into key/value pairs:

fname=John
lname=Doe
email=somewhere@example.com
comments=I love comments

Then it can perform any number of tasks, in this case, sends an email to you. It composes an email, normally to both you and the submittor:

$message= qq/
Dear $FORM{'fname'},<br>
Thank you for your inquiry . . . . etc.
/;

It then opens a mail program on the server and sends it.

The last task here is to output a response so the submittor knows it worked. At it's most basic,

print "content-type: text/html\n\n";
print "Message delivered.";
exit 0;

The same variables used in the mail can be applied here to provide a personalized message:

print "content-type: text/html\n\n";
print "Thank you for your interest, $FORM{'fname'}";
exit 0;

There are many MANY issues to consider, particularly security, because web forms are the most targeted points for a hacker to abuse, using your well-intentioned contact form to spam thousands of recipients. Review your form processor and read up on form abuse before putting one on your site, make sure you don't give yourself another headache to deal with.

One thread on form abuse [webmasterworld.com]- there are many.