使用 CF MX7 无法访问具有相同名称的表单元素

发布于 2024-11-08 00:39:08 字数 3288 浏览 1 评论 0原文

我正在使用 Coldfusion MX7,并且有一个基本表单,其中可以有多个动态添加到表单中的元素。它们具有相同的名称并且都是复选框。表单的示例如下:

<form action="index.cfm?action=index.report" method="post" id="reportForm">
<div class="report my">
    <ul class="connectWith ui-sortable" id="fieldListSelect" aria-disabled="false">
        <li class="field" id="field_profileFn" style="">
            <a class="action" id="action_profileFn" href="index.cfm?action=index.filter.profileFn" style="display: block; ">filter</a> 
            <label for="profileFn">First Name</label>
            <input type="checkbox" name="reportItem" id="profileFn" value="profileFn">
        </li>
        <li class="field" id="field_profileSn" style="">
            <a class="action" id="action_profileSn" href="index.cfm?action=index.filter.profileSn" style="display: block; ">filter</a> 
            <label for="profileSn">Surname</label>
            <input type="checkbox" name="reportItem" id="profileSn" value="profileSn">
        </li>
        <li class="field" id="field_contactDate" style="">
            <a class="action" id="action_contactDate" href="index.cfm?action=index.filter.contactDate" style="display: block; ">filter</a> 
            <label for="contactDate">Contact date</label>
            <input type="checkbox" name="reportItem" id="contactDate" value="contactDate">
        </li>
    </ul>
</div>
</form>

表单发布后,我通过 cfdump 得到以下信息:

<table class="cfdump_struct">
    <tr><th class="struct" colspan="2" onClick="cfdump_toggleTable(this);" style="cursor:hand;" title="click to collapse">struct</th></tr>

        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">CONTACTDATE_FROM</td>
        <td>  Thu May 19 2011 00:00:00 GMT+0100 (GMT Daylight Time) </td></tr> 
        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">CONTACTDATE_TO</td>
        <td> Thu May 19 2011 00:00:00 GMT+0100 (GMT Daylight Time) </td></tr> 
        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">FIELDNAMES</td>
        <td> REPORTITEM[],CONTACTDATE_FROM,CONTACTDATE_TO </td></tr> 
        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">REPORTITEM[]</td>
        <td> profileFn,profileSn,contactDate </td></tr> 
    </table>

报告了元素 REPORTITEM[],并在尝试将其作为变量访问时得到:

<cfset testing = form.reportItem[]>

Invalid CFML construct found on line 6 at column 50.

在尝试以我的方式访问变量时希望我得到以下信息:

<cfset testing = form.reportItem>

Element REPORTITEM is undefined in FORM.

我继承了这段代码,并且它以前必须工作过。 Coldfusion 还没有升级(显然仍然是 CF 7)并且我能想到的服务器端没有任何其他改变。

我的问题:

  • 这只是 CF7 的限制吗?
  • 这应该是正确的还是完全错误的?
  • 如果这不起作用,我将不得不重写相当多的代码,在发布数据后处理它会更容易编码。修改表格会比较费力,那么可以吗?

I am using Coldfusion MX7 and have a basic form which can have several elements that are dynamically added to the form. They are given the same name and are all checkboxes. An example of the form is as follows:

<form action="index.cfm?action=index.report" method="post" id="reportForm">
<div class="report my">
    <ul class="connectWith ui-sortable" id="fieldListSelect" aria-disabled="false">
        <li class="field" id="field_profileFn" style="">
            <a class="action" id="action_profileFn" href="index.cfm?action=index.filter.profileFn" style="display: block; ">filter</a> 
            <label for="profileFn">First Name</label>
            <input type="checkbox" name="reportItem" id="profileFn" value="profileFn">
        </li>
        <li class="field" id="field_profileSn" style="">
            <a class="action" id="action_profileSn" href="index.cfm?action=index.filter.profileSn" style="display: block; ">filter</a> 
            <label for="profileSn">Surname</label>
            <input type="checkbox" name="reportItem" id="profileSn" value="profileSn">
        </li>
        <li class="field" id="field_contactDate" style="">
            <a class="action" id="action_contactDate" href="index.cfm?action=index.filter.contactDate" style="display: block; ">filter</a> 
            <label for="contactDate">Contact date</label>
            <input type="checkbox" name="reportItem" id="contactDate" value="contactDate">
        </li>
    </ul>
</div>
</form>

Once the form is posted I get the following through cfdump:

<table class="cfdump_struct">
    <tr><th class="struct" colspan="2" onClick="cfdump_toggleTable(this);" style="cursor:hand;" title="click to collapse">struct</th></tr>

        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">CONTACTDATE_FROM</td>
        <td>  Thu May 19 2011 00:00:00 GMT+0100 (GMT Daylight Time) </td></tr> 
        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">CONTACTDATE_TO</td>
        <td> Thu May 19 2011 00:00:00 GMT+0100 (GMT Daylight Time) </td></tr> 
        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">FIELDNAMES</td>
        <td> REPORTITEM[],CONTACTDATE_FROM,CONTACTDATE_TO </td></tr> 
        <tr><td class="struct" onClick="cfdump_toggleRow(this);" style="cursor:hand;" title="click to collapse">REPORTITEM[]</td>
        <td> profileFn,profileSn,contactDate </td></tr> 
    </table>

The element REPORTITEM[] is reported and in trying to access this as a variable I get:

<cfset testing = form.reportItem[]>

Invalid CFML construct found on line 6 at column 50.

In trying to access the variable in the way I would expect I get the following:

<cfset testing = form.reportItem>

Element REPORTITEM is undefined in FORM.

I have inherited this code and it MUST have worked previously. Coldfusion has not been upgraded (obviously being CF 7 still) and nothing else has changed server side that I can think of.

My questions:

  • Is this just a limitation of CF7?
  • This should work right or is this totally wrong?
  • I am going to have to re-write quite a bit of this code if this just doesn't work, handling this after the data has been posted would be easier to code. Modifying the form will be more effort, so is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

宫墨修音 2024-11-15 00:39:08

尝试

<cfset testing = form["reportItem[]"]>

这样做,这将通过键“reportItem[]”获取表单结构。

Try doing

<cfset testing = form["reportItem[]"]>

This will fetch the form struct by the key "reportItem[]".

℡Ms空城旧梦 2024-11-15 00:39:08

据我所知,CF7在这方面没有问题。事实上,我很确定你的复选框的值是由浏览器构建的,而不是网络服务器或 CF。

这是我所看到的:

form.variableNamve[]

不起作用,因为该值将以逗号分隔的列表形式返回。

如果没有选中任何复选框,您将遇到未定义的错误,因为如果没有选中具有该名称的复选框,则该变量将不会由浏览器提交,因此不会存在于表单范围中。您应该默认这一点,并且有几种方法可以做到这一点。

您可以创建一个新结构,将复选框名称作为键,空字符串作为值,然后在其顶部添加 structAppend 表单范围。

您可以使用传统的 cfparam 标记。

您可以将具有相同名称的隐藏表单字段和空字符串作为值添加到表单中。这会强制浏览器返回表单字段,即使没有选中任何复选框。

HTH。

As far as I know, CF7 has no problem with this. In fact, I'm pretty sure that the value of your checkboxes is constructed by the browser, not the webserver or CF.

Here's what I see:

form.variableNamve[]

will not work, because the value is coming back as a comma-delimited list.

You will run into the not defined error if no checkboxes are checked, because if no checkboxes with that name are checked then that variable will not be submitted by the browser, and therefore will not exist in the form scope. You should default this, and there are a couple of ways to do it.

You can create a new struct with the checkbox name as a key, the empty string as the value, then structAppend the form scope on top of it.

You can use the traditional cfparam tag.

You can add a hidden form field with the same name and the empty string as a value to the form. This forces the browser to return the form field, even if no checkboxes are checked.

HTH.

和我恋爱吧 2024-11-15 00:39:08

您是通过 jQuery ajax 发布还是使用普通的提交按钮发布。我认为 jQuery 在发布时添加了variablename[],但有办法禁用它。但在提交按钮的情况下,只有至少选中一个复选框,我才会在表单结构中获得复选框。
在这种情况下,请始终将 cfparam 复选框名称设置为默认值。

Are you posting through jQuery ajax or using normal submit button. I think jQuery add variablename[] while posting it but there is way to disable it. But in case of submit button I will get checkbox only in form structure only if atleast one checkbox is checked.
In this case always cfparam checkbox name with your default value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文