ColdFusion Programming/Form results in a text file
Expert: Donald Hammond - 3/13/2008
QuestionQUESTION: Hi, I am using the cffile tag to write to a text file. The resulting text file is uploaded by a peoplesoft application for further processing.
My question is how do I script coldfusion to provide certain attributes like start position, size, etc.?
I would like the form field data in the text file to display in a specific order and position number like, FirstName (start position 7) (size 30)
LastName (start position 37) (size 30)
etc,.
Thanks
Michael
ANSWER: This is not easy and probably won't work very well. The only way to do it tho is to create a variable called something like myFile and then add the form field data in the order you want it. That part is a piece of cake.
Trying to get it to have a specific start position will require coding to count the length of the input data and then add on spaces ( ) to the end of the string to make it equal to the size. This will make the next input string start in the right place. If your first field does not start on the 1 spot then you will have to start the string with spaces to put the first one where you want it to start.
On the other hand if it is greater than the size you have to truncate it which is much easier to do.
Once you have that all into myFile, you write it to the text file.
---------- FOLLOW-UP ----------
QUESTION: If I create a web form with questions with multiple option values such as;
<option value="cat:dog:pets:">animals</option>.
Using cffile can I have the values written in a text file seperately? For example;
pets dog cat -or- dog pets cat
- written and placed seperately in the resulting text file as individual answers.
Is this possible?
AnswerAloha,
Yes it is possible. You just have to seperate them out using list commands.
Like to get the first one you would do :
LISTGETAT(form.droplist,1,":")
So you could easily loop over the value of the option and get the different entries and then do whatever you want with them.