|
Camden Computing Services :: HTML Forms
Camden
Computing Services
HTML Forms
What is a form?
An HTML form is
a section of a web page that
will
display certain fields (text boxes, check boxes, drop-down lists, etc.)
that
can be filled in and transmitted back to the web server. When a
form is filled out and sent back to the web server, we say that the
data from the filled in form was posted
or submitted.
This posted data can be processed by the web server in a variety of
ways. The programs that accept data submitted from HTML forms are
referred to as form processors.
Form
Processors
One of the most
common types of form processors is the form-to-email processor.
The processor takes the data sent from the web browser and formats it
into an email message. A person who fills in a form doesn't need
direct access to an email server in order to use the form. Since
form data is sent back to the web server for processing, it is the web
server which actually contacts an email server in order to send the
resulting message. Where the email message is sent, how it is
formatted, and what data it contains are all things that can be
controlled from inside the processor program or by hidden fields on the form itself.
How do I use
a form?
Camden Computing
Services has created a custom PHP
based form processor which any Camden Rutgers students, faculty or staff
may use to process their forms. If you wish to create your own form processor
you may also do so.
Regardless of
what form processor you use, forms that are designed to generate email
messages all look very similar. The following is an example of how
to use the Rutgers Camden custom PHP form processor:
NOTE: This form is for demonstration purposes only, it is not functional
And here is
the HTML code which created the above sample form: NOTE: The below code will produce a fully functional form.
<?php include "/services/WWW/computing/utilities/MailForm.php"; ?> <FORM METHOD="POST"> <INPUT TYPE="hidden" NAME="RecipientAddresses" VALUE="joe.user@camden.rutgers.edu"> <INPUT TYPE="hidden" NAME="EmailSubject" VALUE="Example Form"> <INPUT TYPE="hidden" NAME="RedirectURL" value="http://www.camden.rutgers.edu/HELP"> <INPUT TYPE="hidden" NAME="RequiredFields" value="email,realname"> <BR> Your e-mail: <INPUT TYPE="text" NAME="email" size=20 maxlength=45> <BR> Your name: <INPUT TYPE="text" NAME="realname" size=25 maxlength=50> <BR> Please enter your message: <TEXTAREA NAME="Message" rows=10 cols=40></TEXTAREA> <BR> <INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form"><BR> <INPUT TYPE="reset" VALUE="Clear Form"> </FORM>
The first thing you
should take note of is the following line:
<?php include "/services/WWW/computing/utilities/MailForm.php"; ?>
This line must be above the <FORM METHOD="POST"> line. The form will not function at all
unless the include appears in your HTML file before <FORM METHOD="POST">.
We recommend that you place
<?php include "/services/WWW/computing/utilities/MailForm.php"; ?>
at the very beginning of your HTML file.
This include statement is
the actual PHP form processor for your form. Without this line, your form will not send any email messages.
Examining the rest of the above
sample you can see that there are three fields that the
person
browsing the page can fill in (Name, Email, and Message).
There
are also fields visible in the HTML code that are not visible in the
form when the HTML is processed and displayed by a web browser...these
are the hidden fields.
There are
some fields, such as EmailSubject, which do not
necessarily
have to be hidden. If you wanted the person who filled out this
form to
be able to specify a different subject for the email message,
you
could have defined the subject field like this:
Subject:<INPUT TYPE="text" NAME="EmailSubject" size=25 maxlength=35>
This would
create a visible field named "EmailSubject" (and labeled Subject:)
that a person could fill in. The field would appear 25 characters
long in the form, but up to 35 characters could be typed into the
field.
That is the meaning of the size and maxlength
attributes.
One of the last things to take note of is the following line:
<INPUT TYPE="submit" NAME="Submit" VALUE="Submit Form">
This line is the "trigger" for the PHP form processor, the NAME
of the submit button must be called Submit, the VALUE (which is what gets displayed on the screen) can but whatever you like. The PHP form processor will not do anything until it detects that the Submit button was pressed.
The following is a listing of the reserved variable names that our form processor uses:
| Variable NAME | Description |
| RecipientAddresses | This is a comma separated list of email addresses that you would like the form results sent to. Only email addresses ending in "rutgers.edu" are supported, outside email addresses (like hotmail or yahoo) are not supported. |
| FromFormat | This will allow you to customize the "From" line of the email you receive. This is convenient if you want the email to appear as though it came from the person who submitted it. Simply specify the field names that the form processor should use. A simply example would be:
<input type="hidden" name="FromFormat" value="realname <email>"> |
| EmailSubject | This will be the subject line of the email that is sent to the recipients. (optional, a default value of "ONLINE FORM SUBMISSION" will used if not set) |
| EnvReport | This allows you to add environment variable values to the end of the email. An example would be:
<input type="hidden" name="EnvReport" value="REMOTE_ADDR,HTTP_USER_AGENT"> |
| RedirectURL | This is the URL that a user will be directed to after submitting the form. If you do not set this option, the user will get a plain "Thank you for your submission." message. |
| RequiredFields | This is a comma separated list of field (variable) names that you are requiring the users to fill in before your form can be submitted. (optional) |
| MultiLineVars | This is a comma separated list of field (variable) names that should be considered multiline, so that the form submission emails looks nicer. (optional)
<input type="hidden" name="MultiLineVars" value="MailingAddress,ClassSchedule"> |
| RecipientFileList | Since spammers are constantly searching web pages for email addresses, you can choose to store your recipient email list inside of a text file on the server. Simple specify the path to the file, like so:
<input type="hidden" name="RecipientFileList" value="/path/to/emaillist.txt"> |
| CSVFile | NOTE: You must contact Camden Computing Services, to setup a CSV file before you can use this option. This option gives you the ability to store all of your form submissions in a CSV file on the server. CSV stands for "Comma Separated Value" file, which many office applications (like Excel) can import into a spreadsheet. |
| SendEmail | This option can either be set to "yes" or "no". This option is by default "yes", so if you do not set this option, your form will automatically send an email. Setting this option to "no" is most useful if you are using the above CSVFile option, that way all of the form results are stored in the CSVFile, and you don't have to constantly receive email messages when your form is submitted. |
There are many different pre-made PHP scripts that can process forms
and send email. Some HTML editing software can even generate
simple PHP form processors for you and embed them into your web
pages. It's important to fully read through any documentation supplied by the
authors before attempting to use any of the more advanced features of
any form processor. Camden Computing Services only supports their
custom PHP based form processor. We can provide some assistance with the setup and configuration of simple HTML forms that use our PHP form processor. If you are looking to setup an advanced form, you may need to contact your departmental UCS/IT staff or an outside vendor for support.
|