Bri*_*Bri 3 forms coldfusion dynamic
我这里有一个有趣的问题......
<cfloop from="1" to="#form.countField#" index="i">
<cfif isdefined('form["semester#i#"]')>
<cfquery name = "insertCourses" datasource="cas_evaluation">
INSERT INTO courses (faculty, semester, course, students, hours, team_taught, first_time, ec_dl, online, course_revision )
VALUES ( '#form.name#', '#form['semester#i#']#', '#form['course#i#']#', '#form['numstudents#i#']#', '#form['hours#i#']#', '#form['team#i#']#', '#form['firsttime#i#']#', '#form['ec_dl#i#']#', '#form['online#i#']#', '#form['revision#i#']#')
</cfquery>
</cfif>
</cfloop>
Run Code Online (Sandbox Code Playgroud)
基本上,我有一些可以添加或删除的动态字段.(这些是字段行btw ...)我编码的方式...如果用户删除中间的一行...(他们删除第2行,第1行和第3行留下......)问题因为循环正在寻找它但显然不存在.所以我尝试检查是否有一个字段被定义...但它不喜欢isdefined变量的语法.. :(
有什么建议?
我不太明白这个问题.所以这不起作用?
<cfif isdefined('form["semester#i#"]')>
Run Code Online (Sandbox Code Playgroud)
使用
<cfif structKeyExists(form, "semester#i#")>
Run Code Online (Sandbox Code Playgroud)
cfparam和isDefined不喜欢阵列式的语法.在您的情况下,您还可以使用:
<cfif isdefined('form.semester#i#')>
Run Code Online (Sandbox Code Playgroud)
就个人而言,这不是我喜欢的风格,但它应该可以正常工作.