Coldfusion 错误 500 复杂对象类型无法转换为简单值

问题描述 投票:0回答:1

我有如下所示的 html 部分

<cfset formSections = [
    {
        title: "Client Information",
        fields: [
            {label: "Name - First and Last (both)", type: "text", name: "FullName", maxlength: 150},
            {label: "Email Address", type: "text", name: "Email", maxlength: 150},
            {label: "Home Address", type: "textarea", name: "Address1", rows: 4, cols: 50}
        ]
    }
]

和formData一样

<cfset formData = {"Email" : "[email protected]", "Fullname" : "Hans M"}>

我正在尝试创建一个如下所示的 html 表单

<cfloop array="#formSections#" index="section">

    <table class="formTable">
        <tr>
            <td height="35" colspan="2" align="left" valign="middle" bgcolor="##CCCCFF">
                <span style="font-weight: bold">#section.title#</span>
            </td>
        </tr>
        <cfloop array="#section.fields#" index="field">
            <cfif StructKeyExists(formData, field.name)>
                <tr>
                    <td class="name">#field.label#</td>
                    <td>
                        <cfif field.type IS "text">
                            <input type="#field.type#" name="#field.name#" maxlength="#field.maxlength#"
                                value="#EncodeForHTML(formData[field.name])#">
                        </cfif>
                    </td>
                </tr>
            <cfelse>
                <!-- If the item.name does not exist in formData, output the form element without a value -->
                <cfif field.type IS "text">
                    <label for="#field.name#">#field.name#:</label>
                    <input type="#field.type#" name="#field.name#" id="#field.name#" value="" /><br/>
                </cfif>
            </cfif>
        </cfloop>
    </table>
    <br/>

</cfloop>

但我收到错误

500 Complex object types cannot be converted to simple values.

此错误出现在

value="#EncodeForHTML(formData[field.name])#"

但不知道如何解决这个问题..任何帮助..提前致谢

coldfusion
1个回答
0
投票

您的示例代码运行得很好。我假设您遇到了不同

formData
内容的问题?

该错误告诉您

formData
中的值之一被视为“复杂”,例如结构体、数组或对象。您可以通过用以下内容包裹投掷线来捕获坏值:

<cfif isSimpleValue(formData[field.name])>
    <input type="#field.type#" name="#field.name#" maxlength="#field.maxlength#" value="#EncodeForHTML(formData[field.name])#">
<cfelse>
    <cfdump label="#field.name# is the culprit" var="#formData[field.name]#" abort>
</cfif>
© www.soinside.com 2019 - 2024. All rights reserved.