ColdFusion获取客户端表单提交数据并写入/附加到csv文件

jfgube3f  于 2023-03-21  发布在  其他
关注(0)|答案(1)|浏览(125)

我有一个相对基本的反馈表在我的网站上的作品。
我试图建立另一个类似的形式,但不使用邮件程序,我只是想存储在一个csv文件的数据。
我正在使用我现有的代码并试图修改它,同时研究如何完成这一点(我只知道非常基本的ColdFusion东西)。
有整个代码与邮件部分的工作,我试图修改数据推到csv文件。

<!---<cfmail to="me@email.com" from="feedback@emailcom" cc="data@email.com" subject="Response">
    <cfloop list="#form.fieldnames#" index="el">
        #el#: #form[el]# #chr(13)# #chr(10)#
    </cfloop>
    URL #CGI.http_referer#
    IP #CGI.remote_addr#
    User Agent #CGI.http_user_agent#
    Date #DateFormat( Now(), "mmm d, yyyy" )# at #TimeFormat( Now(), "hh:mm TT" )#
</cfmail>--->

<cfset headerColumn = "no.,prompt,name,actual_name,email,comments,auth,gcaptcha">
<cfset fileOutputPath = "C:\path\to\data">               
           
<cffile
    action="write"
    file="#fileOutputPath#\submissions.csv" 
    output="#headerColumn#"
    nameconflict="overwrite"
    addnewline="yes"
>
                   
<cfloop query="getSubmissions" list="#form.fieldnames#" index="el">
    <cfset data = #el#,#form[el]#,#chr(13)#,#chr(10)# >
    <!--- <cfset out_cols = "#prompt#,#name#,#actual_name#,#email#,#comments#,#auth#,#gcaptcha#"> --->
    <cffile
        action="append"
        file="#fileOutputPath#\submissions.csv"
        output="#data#"
        addnewline="yes"
    >
</cfloop>

这个的好处是:

<cfloop list="#form.fieldnames#" index="el">
     #el#: #form[el]# #chr(13)# #chr(10)#
</cfloop>

我想这只需要遍历表单域就行了,大概是1还是100都没关系。
我不知道我是否必须显式地设置csv文件的每个字段,尽管在定义头文件时这样做是有意义的。

form[0] = name;
form[5] = comments;

目前我得到一个错误,我假设串联是不正确的。有人知道我是怎么做的吗?
如果您需要查看应用程序的其他部分,请让我知道,但邮件程序部分工作,我只是试图适应它写到文件。
短暂性脑缺血发作

  • 编辑 *

下面是我看到的错误:

Column  27
Detail  ColdFusion was looking at the following text:<p>,</p><p>The CFML compiler was processing:<ul><li>A cfset tag beginning on line 23, column 10.<li>A cfset tag beginning on line 23, column 10.</ul>
KnownColumn 26
KnownLine   23
KnownText   #
Line    23
Message Invalid CFML construct found on line 23 at column 27.
Snippet <cfset data = #el#,
StackTrace  coldfusion.compiler.ParseException: Invalid CFML construct found on line 23 at column 27.
x4shl7ld

x4shl7ld1#

<cfset data = #el#,#form[el]#,#chr(13)#,#chr(10)# >

这一行需要引号。在变量上加上#,它将输出正确的数据,同时保留标准的字符串值。

<cfset data = "#el#,#form[el]#,#chr(13)#,#chr(10)#">

相关问题