Fog Creek Software
Discussion Board




Knowledge Base
Documentation
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 http://lumbroso.com/scripts/formmail.php  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:  http:www.yourdomain.com/files/

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="http://www.yourDomain.com/phpFormMail/formmail.php">

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="http://www.yourdomain.com/magicNumber 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: http://kevinsherwood.com/corcu/Members_Area/fog0000000046.html

Hope this is useful to someone :-)

ks

Kevin Sherwood
Wednesday, February 13, 2002

Great tip, Kevin! Thanks.

Darren Collins
Wednesday, February 13, 2002

*  Recent Topics

*  Fog Creek Home