I figured it out

July 3, 2003 by Mike Bam

I spent this morning trying things out and my mistake was simple, i was using an "write" command instead of "append." So, below is the coding to perform this actually simple task. Hope it comes in handy.

This requires 3 files (if you want to use it with a form)

This is the actual code that adds to the file:

Put this code in a .cfm file (logcode.cfm here):

<cffile action="append" file="log.cfm" output="#form.input#" addnewline="Yes">

I think you may have to put the file in its root location on the server, but I'm not sure. I would do it just to be safe (ie: Z:/websites/domain.com/logs/log.cfm")

This is the code you need on the form in a separate .cfm file at any part of your website:

<form action="logcode.cfm" method="post">
Name: <input type="text" name="input"><p>
<input type="submit" value="Submit">
</form>

Last, you need to create the file the log will be in, name it "log.cfm" or whatever you choose so long as it corresponds to what is in the first file.

Everytime someone inputs that information in you form, it will be automatically added to log.cfm. I found it makes an easy visitor logging tool by replacing it as a form and putting it simply as a code on a page, where instead of #form.input# I use #remote_addr# to gather the IP.

Thanks!