Fog Creek Software
Discussion Board

Knowledge Base
Terry's Tips
Darren's Tips

One way of handling Web Forms with CD

Building my latest site has prompted me to create a bunch of forms for submitting data to the webmaster.  I've done a bunch of this in the past with a variety of scripting languages.  So here is the easiest approach I have found for doing this in CD.  The only requirement is to have php (or perl) available on your server, which I have found to be pretty typical at most hosting facilities.

1.  Download phpFormMail from  I'm using formmail because :
*  it's free
*  has input checking for phone numbers and zip codes
*  handles file uploads gracefully. 
There's a perl version available as well (look for link halfway down page).

2.  Install phpFormMail on your server.  Basically unzipping the download and ftp'ing the files up to your server.  I put them in their own directory instead of including them in the .cty file as I anticipate having different sites using the same functionality.

3.  Setup the following variables in CD:

fileRoot : this is the url of where you want uploaded files to go. ex:

formRecipientEmail : email address of where you want all of your forms to be emailed to.  If different forms go to different people, ignore this.

emailForm :
<form method="post" enctype="multipart/form-data" action="">

4.  Now creating an email form is as simple as inserting the following code in your article body:

{$. emailForm $}
<INPUT type="hidden" name="recipient" value="{$.formRecipientEmail $}">
<INPUT type=hidden value="Name of the subject" name=subject>
<INPUT type=hidden value=" of your response article" name=redirect>  I use a single page for this but you can create one for each form as necessary.

There are a lot of other tags that you can use for requiring input parameters, setting the path of where the files are posted, limited file sizes, etc.  But these are the basics. 

To see it in action:

Hope this is useful to someone :-)


Kevin Sherwood
Wednesday, February 13, 2002

Great tip, Kevin! Thanks.

Darren Collins
Wednesday, February 13, 2002

*  Recent Topics

*  Fog Creek Home