MailFormTutorial
ThistutorialwillshowyouhowtomakeuseofSIUE’smailformscripttoallowwebusersto
contactyouviaemailregardinganythingyouwish. Thisscriptifmostusefulforreceiving
questions,comments,orrequests.
Whenyouhaveselectedwhereyouwouldliketheformonyourwebpage,inserttheselinesof
codetostart:
<formname="mail"method="post"action="http://www.siue.edu/cgibin/FormMail.pl">
<inputtype="submit"value="Submit"></form>
Everythingyouenterfortheformwillfallbetweenthesetwolinesofcode.
Totellthescriptwheretosendtheformtoonceitisfilledoutinsertthisline:
<inputtype="hidden"name="recipient"value="somebody@siue.edu">
Youwillwanttoreplacesomebod[email protected]”withtheindividualyouwouldliketoreceive
theemails.
Regardlessof whatyourpurposefortheformis,youwillmostlikelyincludeanamefieldas
wellasareturnemailaddressincaseyoushouldwishtocontacttheindividual.
<inputtype="text"id="realname"name="realname"onfocus="this.value=’’"><label
for="realname">Name</label>
<inputtype="text"id="email"name="email"onfocus="this.value=’’"><label
for"email">EMail</label>
Neitheroneofthesefieldsisrequired,however,ifyouchoosetoomittheemailaddressfield
thereisagoodchancetheSIUEspamfilterwillcatchitastheemailappearstobesentfromno
one. Tokeepyourform accessibletouserswithdisabilities,includetheidtaglabeltags. The
idofthefieldshouldmatchtheforattributeinthelabel. Inthiscase,theid“realname”matches
theforattribute“realname”.
Theonfocus="this.value=’’"letsyouputtextinthefieldandhaveitdisappearwhentheuser
clickswithinthefieldtoentertheirowndata. Intheaboveexamplestheplaceholdertext
wouldbeNameandEMail. Thistextwouldappearinthetextboxinitially,butdisappearwhen
theuserclicksinsidethebox. Thisishelpfultoallofyourusers.
Anyfieldsyouwishtoaddotherthanthese,simplyusethesamesyntaxandchangeittofityour
needs. Suchas:
<inputtype="text"id="color"name="favoritecolor"onfocus="this.value=’’"><label
for="color">FavoriteColor</label>
Youcanalsoinsertasimilarboxforlargerentries,suchascomments,likethis:
<labelfor="comments"></label>
<textareaname="comments"id="comments"rows="10"cols="40"id="comments"
onfocus="this.value=’’">PleaseEnteryourcomments.</textarea>
Youcouldalsopresenttheuserwithoptions,suchascheckboxesorradiobuttonsinsteadofa
textfield,likethis:
<inputtype="radio"id="pizza"name="FavoriteFood"value="Pizza"><label
for="pizza">Pizza</label>
<inputtype="radio"id="steak"name="FavoriteFood"value="Steak"><label
for="steak">Steak</label>
<inputtype="radio"id="edible"name="FavoriteFood"value="IsitEdible?"><label
for="edible">IsitEdible?</label>
<inputtype="checkbox"id="sports"name="Ilikethefollowing"value="Sports"><label
for="sports">Sports</label>
<inputtype="checkbox"id="tv"name="Ilikethefollowing"value="TV"><label
for="tv">TV</label>
<inputtype="checkbox"id="cooking"name="Ilikethefollowing"value="Cooking"><label
for="cooking">Cooking</label>
Therearemanyconfigurationoptionsaswellforthisform. Forinstance,youcanrequireauser
tofillincertainfieldsbeforesubmittingtheform,suchasemailandrealname,likethis:
<inputtype="hidden"name="required"value="email,realname">
Apopularoptionistoredirecttheusertoanewpagetoconfirmtheformsubmission.
<inputtype="hidden"name="redirect"
value="http://www.siue.edu/yourspace/yourthankyoupage.html">
Ifyouusedalloftheaboveoptionsyourformwouldlooklikethiswhenyou’redone.
<formname="mail"method="post"action="http://www.siue.edu/cgibin/FormMail.pl">
<inputtype="hidden"name="recipient"value="somebody@siue.edu">
<inputtype="hidden"name="required"value="email,realname">
<inputtype="hidden"name="redirect"
value="http://www.siue.edu/yourspace/yourthankyoupage.html">
<inputtype="text"id="realname"name="realname"onfocus="this.value=’’"><label
for="realname">Name</label>
<inputtype="text"id="email"name="email"onfocus="this.value=’’"><label
for"email">EMail</label>
<inputtype="text"id="color"name="favoritecolor"onfocus="this.value=’’"><label
for="color">FavoriteColor</label>
<labelfor="comments"></label>
<textareaname="comments"id="comments"rows="10"cols="40"id="comments"
onfocus="this.value=’’">PleaseEnteryourcomments.</textarea>
<inputtype="radio"id="pizza"name="FavoriteFood"value="Pizza"><label
for="pizza">Pizza</label>
<inputtype="radio"id="steak"name="FavoriteFood"value="Steak"><label
for="steak">Steak</label>
<inputtype="radio"id="edible"name="FavoriteFood"value="IsitEdible?"><label
for="edible">IsitEdible?</label>
<inputtype="checkbox"id="sports"name="Ilikethefollowing"value="Sports"><label
for="sports">Sports</label>
<inputtype="checkbox"id="tv"name="Ilikethefollowing"value="TV"><label
for="tv">TV</label>
<inputtype="checkbox"id="cooking"name="Ilikethefollowing"value="Cooking"><label
for="cooking">Cooking</label>
<inputtype="submit"value="Submit">
</form>
Youwillobviouslywanttodosomeformattingwithbreaks,paragraphs,orastylesheetasthis
wouldprobablybeprettymessyandnotverydescriptivethewayitis.
Hereisanexampleforyoutoreferenceifyoushouldneedto. Youcanrightclickanywhereon
thepageandchooseviewpagesourcetoseethecode.
http://www.siue.edu/web/form_example.shtml
Belowaretheotherconfigurationoptionsalongwithabriefdescription.
Field: subject
Description:Thesubjectfieldwillallowyoutospecifythesubjectthatyouwishtoappearinthe
emailthatissenttoyouafterthisformhasbeenfilledout. Ifyoudonothavethisoption
turnedon,thenthescriptwilldefaulttoamessagesubject:WWWFormSubmission
Syntax:
Ifyouwishtochoosewhatthesubjectis:
<inputtype="hidden"name="subject"value="YourSubject">
Toallowtheusertochooseasubject:
<inputtype="text"name="subject">

Field: email
Description:Thisformfieldwillallowtheusertospecifytheirreturnemailaddress. Ifyou
wanttobeabletoreturnemailtoyouruser,Istronglysuggestthatyouincludethisformfield
andallowthemtofillitin. ThiswillbeputintotheFrom:fieldofthemessageyoureceive. If
youwanttorequireanemailaddresswithvalidsyntax,addthisfieldnametothe'required'field.
Syntax:
<inputtype="text"name="email">

Field: realname
Description:Therealnameformfieldwillallowtheusertoinputtheirrealname. Thisfieldis
usefulforidentificationpurposesandwillalsobeputintotheFrom:lineofyourmessage
header.
Syntax: <inputtype="text"name="realname">

Field: redirect
Description:IfyouwishtoredirecttheusertoadifferentURL,ratherthanhavingthemseethe
defaultresponsetothefilloutform,youcanusethishiddenvariabletosendthemtoapremade
HTMLpage.
Syntax:
TochoosetheURLtheywillendupat:
<inputtype="hidden"name="redirect"value="http://your.host.com/to/file.html">To
allowthemtospecifyaURLtheywishtotraveltooncetheformisfilledout:
<inputtype="text"name="redirect">

Field: required
Description:Youcannowrequireforcertainfieldsinyourformtobefilledinbeforetheuser
cansuccessfullysubmittheform. Simplyplaceallfieldnamesthatyouwanttobemandatory
intothisfield. Iftherequiredfieldsarenotfilledin,theuserwillbenotifiedofwhattheyneed
tofillin,andalinkbacktotheformtheyjustsubmittedwillbeprovided.
Touseacustomizederrorpage,see'missing_fields_redirect'
Syntax:
Ifyouwanttorequirethattheyfillintheemailandphonefieldsinyourform,sothat
youcanreachthemonceyouhavereceivedthemail,useasyntaxlike:
<inputtype="hidden"name="required"value="email,phone">

Field: env_report
Description:AllowsyoutohaveEnvironmentvariablesincludedintheemailmessageyou
receiveafterauserhasfilledoutyourform. Usefulifyouwishtoknowwhatbrowserthey
wereusing,whatdomaintheywerecomingfromoranyotherattributesassociatedwith
environmentvariables. Thefollowingisashortlistofvalidenvironmentvariablesthatmight
beuseful:
REMOTE_HOST Sendsthehostnamemakingarequest.
REMOTE_ADDR SendstheIPaddressoftheremotehostmakingtherequest.
REMOTE_USER Ifserversupportsauthenticationandscriptisprotected,thisis
theusernametheyhaveauthenticatedas.*Thisisnotusuallyset.*
HTTP_USER_AGENT Thebrowsertheclientisusingtosendtherequest.
Thereareothers,buttheseareafewofthemostuseful. Formoreinformationon
environmentvariables,see:
http://www.cgiresources.com/Documentation/Environment_Variables/
Syntax:
Ifyouwantedtofindtheremotehostandbrowsersendingtherequest,youwouldput
thefollowingintoyourform:
<inputtype="hidden"name="env_report"value="REMOTE_HOST,
HTTP_USER_AGENT">

Field: sort
Description:Thisfieldallowsyoutochoosetheorderinwhichyouwishforyourvariablesto
appearintheemailthatFormMailgenerates. Youcanchoosetohavethefieldsorted
alphabeticallyorspecifyasetorderin whichyouwantthefieldstoappearinyourmailmessage.
Byleavingthisfieldout,theorderwillsimplydefaulttotheorderinwhichthebrowsersends
theinformationtothescript(whichisusuallytheexactsameorderastheyappearedintheform.)
Whensortingbyasetorderoffields,youshouldincludethephrase"order:"asthefirstpartof
yourvalueforthesortfield,andthenfollowthatwiththefieldnamesyouwanttobelistedinthe
emailmessage,separatedbycommas. Version1.6allowsalittlemoreflexibilityinthelisting
oforderedfields,inthatyoucanincludespacesandlinebreaksinthefieldwithoutitmessingup
thesort. Thisishelpfulwhenyouhavemanyformfieldsandneedtoinsertalinewrap.
Syntax:
Tosortalphabetically:
<inputtype="hidden"name="sort"value="alphabetic">
Tosortbyasetfieldorder:
<inputtype="hidden"name="sort"value="order:name1,name2,
name3,etc...">

Field: print_config
Description:print_configallowsyoutospecifywhichoftheconfigvariablesyouwouldliketo
haveprintedinyouremailmessage.Bydefault,noconfigfieldsareprintedtoyouremail.
Thisisbecausetheimportantformfields,likeemail,subject,etc.areincludedintheheaderof
themessage. Howeversomeusershaveaskedforthisoptionsotheycanhavethesefields
printedinthebodyofthemessage. Theconfigfieldsthatyouwishtohaveprintedshouldbein
thevalueattributeofyourinputtagseparatedbycommas.
Syntax:
Ifyouwanttoprinttheemailandsubjectfieldsinthebodyofyourmessage,you
wouldplacethefollowingformtag:
<inputtype="hidden"name="print_config"value="email,subject">

Field: print_blank_fields
Description:print_blank_fieldsallowsyoutorequestthatallformfieldsareprintedinthereturn
HTML,regardlessofwhetherornotthey werefilledin. FormMaildefaultstoturningthisoff,
sothatunusedformfieldsaren'temailed.
Syntax:
Ifyouwanttoprintallblankfields:
<inputtype="hidden"name="print_blank_fields"value="1">

Field: title
Description:Thisformfieldallowsyoutospecifythetitleandheaderthatwillappearonthe
resultingpageifyoudonotspecifyaredirectURL.
Syntax:
Ifyouwantedatitleof'FeedbackFormResults':
<inputtype="hidden"name="title"value="FeedbackFormResults">

Field: return_link_url
Description:ThisfieldallowsyoutospecifyaURLthatwillappear,asreturn_link_title,onthe
followingreportpage. Thisfieldwillnotbeusedifyouhavetheredirectfieldset,butitis
usefulifyouallowtheusertoreceivethereporton thefollowingpage,butwanttoofferthema
waytogetbacktoyourmainpage.
Syntax:
<inputtype="hidden"name="return_link_url"
value="http://your.host.com/main.html">

Field: return_link_title
Description:Thisisthetitlethatwillbeusedtolinktheuserbacktothepageyouspecifywith
return_link_url. Thetwofieldswillbeshownontheresultingformpageas:
<ul>
<li><ahref="return_link_url">return_link_title</a>
</ul>
Syntax:
<inputtype="hidden"name="return_link_title"
value="BacktoMainPage">

Field: missing_fields_redirect
Description:ThisformfieldallowsyoutospecifyaURLthatuserswillberedirectedtoifthere
arefieldslistedintherequiredformfieldthatarenotfilledin. Thisissoyoucancustomizean
errorpageinsteadofdisplayingthedefault.
Syntax:
<inputtype="hidden"name="missing_fields_redirect"
value="http://your.host.com/error.html">

Field: background
Description:Thisformfieldallowsyoutospecifyabackgroundimagethatwillappearifyoudo
nothavetheredirectfieldset. Thisimagewillappearasthebackgroundtotheformresults
page.
Syntax:
<inputtype="hidden"name="background"
value="http://your.host.com/image.gif">

Field: bgcolor
Description:Thisformfieldallowsyoutospecifyabgcolorfortheformresultspageinmuch
thewayyouspecifyabackgroundimage.Thisfieldshouldnotbesetiftheredirectfieldis.
Syntax:
ForabackgroundcolorofWhite:
<inputtype="hidden"name="bgcolor"value="#FFFFFF">

Field: text_color
Description:Thisfieldworksinthesamewayasbgcolor,exceptthatitwillchangethecolorof
yourtext.
Syntax:
ForatextcolorofBlack:
<inputtype="hidden"name="text_color"value="#000000">

Field: link_color
Description:Changesthecoloroflinksontheresultingpage. Thisworksinthesamewayas
text_colorandshouldnotbedefinedifredirectis.
Syntax:
ForalinkcolorofRed:
<inputtype="hidden"name="link_color"value="#FF0000">

Field: vlink_color
Description:Changesthecolorofvisitedlinksontheresultingpage.Thisworksexactlythe
sameaslink_color. Shouldnotbesetifredirectis.
Syntax:
ForavisitedlinkcolorofBlue:
<inputtype="hidden"name="vlink_color"value="#0000FF">

Field: alink_color
Description:Changesthecolorofactivelinksontheresultingpage.Thisworksexactlythesame
aslink_color. Shouldnotbesetifredirectis.
Syntax:
ForavisitedlinkcolorofBlue:
<inputtype="hidden"name="alink_color"value="#0000FF">

Anyotherformfieldsthatappearinyourscriptwillbemailedbacktoyouanddisplayedonthe
resultingpageifyoudonothavetheredirectfieldset.