Coldfusion 中的 CFForm 与 Form

发布于 2024-11-14 08:25:22 字数 258 浏览 5 评论 0原文

我在 Coldfusion 中使用普通表单和输入字段已经有一段时间了,但最近发现 cfinput 标签会自动阻止我的一些 xss 攻击。这让我想知道,在 Coldfusion 中使用 cffrom 和 cfinput 相对于普通形式和输入标签是否有任何缺点。

我在短时间内发现的唯一缺点是它向页面添加了 2 个外部样式表和 1 个脚本标记。

简而言之:

在冷融合中使用 CFFORM 相对于 FORM 有何优点和缺点?

I have been using plain forms and input fields in coldfusion for some time now but recently discovered that cfinput tags will automagically prevent some xss attacks for me. This has made me wonder, if there is any disadvantages to using cffrom and cfinput over normal form and input tags in coldfusion.

The only disadvantage I have found in the short time looking into it is that it adds 2 external style sheets and 1 script tag to the page.

so in short:

What are the advantages and disadvantages of using CFFORM over FORM in coldfusion?

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

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

发布评论

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

评论(4

葬心 2024-11-21 08:25:22

我更喜欢围绕我的表单编写自己的 JS。我当时开始使用 cfform,但最终想做比 cfform 能够处理的更强大的事情(验证等)。这迫使我学习 JS,从那以后我就很高兴编写自己的 JS。

所以我想我会说一个很大的缺点是你受限于 cfform 可以处理的内容。根据您的情况,这可能没问题。

我很久以前遇到的另一个缺点(公平地说,可能已经解决了),是 cfform 生成的 JS 会与我手写的 JS 发生冲突或干扰。

这肯定会取决于偏好。使用 cfform 或常规形式既不是“正确”也不是“错误”。对我来说,我更喜欢能够手动执行任何需要执行的操作,因为没有任何限制/限制。

I prefer to write my own JS around my forms. I started out with cfform back in the day, but eventually wanted to do more robust things (validations, etc) than cfform was able to handle. That forced me to learn JS, and I've been very happy writing my own JS since.

So I guess I'd say one big drawback is that you're restricted to what cfform can handle. Depending on your situation, that might be fine.

Another drawback that I ran into a long time ago (which to be fair, may have been addressed since), is that the JS generated by cfform would conflict or interfere with my hand-written JS.

It'll certainly come down to preference. It's neither "right" nor "wrong" to use cfform or regular forms. For me, I prefer to be able to do whatever manipulation I need to do manually, as there are no restrictions/limitations.

骄兵必败 2024-11-21 08:25:22

我对 & 是又爱又恨。

要获得与 CFFORM 提供的相同的 XSS 保护,只需将 htmlEditFormat() 包裹在 value="" 周围,如下所示:

<input name="x" value="#htmlEditFormat(x)#">

为了获得更好的 XSS 保护,请使用 OWASP Enterprise Security API(.jar 包含在 CF9 最新修补程序之一中)

我喜欢如何轻松地执行 ajaxified 表单,而无需编写 JS,但我讨厌它生成大量丑陋的 JavaScript 并为相当简单的东西加载大量 JS 和 css 文件。因此,我决定仅将 cfform 用于内部站点,而不用于面向公众的站点(性能问题)。

除了 ajax 功能之外,接受 CF 布尔值的 checked 属性和使用查询对象填充 select 是 cfinputcfselect 提供的功能,这些功能可以非常有用。

使用正确的工具完成正确的工作。如果您发现 的功能很有用,请使用它。只需了解其局限性,然后自行决定。

I have a love-hate relationship with <cfform> & <cfinput>.

To have the same xss protection that CFFORM provides, just wrap htmlEditFormat() around value="" in regular like so:

<input name="x" value="#htmlEditFormat(x)#">

For even better XSS protection, use OWASP Enterprise Security API (.jar included in one of the CF9 latest hotfixes)

I love how I can do ajaxified form easily without writing JS, but I hate how it generates lots of ugly JavaScript and loads up lots of JS and css files for something rather simple. So I've decided to use cfform for internal sites only and not for public facing site (performance issue).

Other then the ajax features, the checked attribute that accepts CF boolean and populating select with query object are features that cfinput and cfselect provide which can be quite useful.

Use the right tool for the right job. If you found the feature of <cfform> useful, use it. Just know its limitations, and decide for yourself.

我只土不豪 2024-11-21 08:25:22

我使用 ColdFusion 已有近 14 年了。 CF 之所以成为如此强大的产品,是因为它使新用户能够在没有太多了解的情况下快速完成大量工作,并且它也使火箭科学家能够快速构建真正强大且安全的应用程序。

CFFFORM、CFINPUT、CFLAYOUT、CFPOD 是为新用户创建的标签。基本上,它们是辅助轮。如果您是网络开发新手,您应该尝试一下这个标签。随着经验的积累,您将希望放弃这些标签并转向其他技术来创建更强大的应用程序。

这些标签没有任何问题,就像辅助轮没有任何问题一样。您只需要知道每项工作都有合适的工具即可。事实上,每项工作都有很多合适的工具。

目前,我正在开发一个ColdFusion 9 / jQuery / SQL Server Intranet,用于构建外部网站。我这样做时没有使用单个表单标签。而且,我完全是在 CFSCRIPT 中完成的。哇!

使用 jQuery,您不需要表单。您只需要输入。以下是我在 CFSCRIPT 中创建输入的方法。

<cfscript>
Options = "";
for (i = 1; i lte 10; i++) {
  Options = Options & wrapOption("Some choice #i# ", i);
}
SelectBox = wrapSelect(Options, "MySelectID");
writeOutput(SelectBox);
SecretDiv = wrapDiv("", "", "MyDivID");
writeOutput(SecretDiv);
</cfscript>

用于创建 HTML 的用户定义函数位于我的 UDF_Library.cfm 文件中:

// WRAP SELECT
function wrapSelect(SelectContent, Class, ID) {
    LOCAL.SelectContent = ARGUMENTS.SelectContent;
    LOCAL.Properties = "";
    // CLASS
    if (isDefined("ARGUMENTS.Class")) {
        LOCAL.Properties = LOCAL.Properties & " class='#ARGUMENTS.Class#'";
    }
    // ID
    if (isDefined("ARGUMENTS.ID")) {
        LOCAL.Properties = LOCAL.Properties & " id='#ARGUMENTS.ID#'";
    }
    LOCAL.Item = "<select #LOCAL.Properties#>#LOCAL.SelectContent#</select>";
    return LOCAL.Item;
}
// WRAP OPTION
function wrapOption(Content, Value, Selected) {
    LOCAL.Content = ARGUMENTS.Content;
    LOCAL.Properties = " value='#ARGUMENTS.Value#'";
    // SELECTED
    if (isDefined("ARGUMENTS.Selected") and (ARGUMENTS.Selected eq "selected")) {
        LOCAL.Properties = LOCAL.Properties & " selected";
    }
    LOCAL.Item = "<option #LOCAL.Properties#>#LOCAL.Content#</option>";
    return LOCAL.Item;
}
// CREATE DIV
function wrapDiv(Content, Class, ID) {
    LOCAL.Properties = "";
    // CLASS
    if (isDefined("ARGUMENTS.Class")) {
        LOCAL.Properties = LOCAL.Properties & " class='#ARGUMENTS.Class#'";
    }
    // ID
    if (isDefined("ARGUMENTS.ID")) {
        LOCAL.Properties = LOCAL.Properties & " id='#ARGUMENTS.ID#'";
    }
    LOCAL.Item = "<div #LOCAL.Properties#>#ARGUMENTS.Content#</div>";
    return LOCAL.Item;
}

我使用 jQuery 并通过其类或 ID 引用每个元素。如果这样做,您可以将每个元素中的数据提交给 ajax 调用,如下所示:

<script type="text/javascript">
$(document).ready(function() {
$("#MySelectID").change(function() {
   MyID = $("#MySelectID").val();
   $("#MySecretDiv").load("CoolQuery.cfm?UserID"+MyID);
});


});
</script>

要点是,只要您使用 CFFORM 和 CFINPUT,您就无法执行所有真正强大的 jQuery 功能。但是,您需要这些标签才能开始。

2012 年将是 ColdFusion 和 jQuery 强大力量的一年!

祝你好运!

I have been using ColdFusion for almost 14 years. The reason that CF is such a kick-ass product is that empowers new users to get a lot of work done quickly with not much understanding and it enables rocket scientists to build really powerful and secure applications quickly too.

CFFFORM, CFINPUT, CFLAYOUT, CFPOD are tags that are created for new users. Basically, they are training wheels. If you're new to web development, you should give this tags a try. As you gain experience, you'll want to drop these tags and move onto other techniques to create more robust applications.

There's nothing wrong with these tags, just like there's nothing wrong with training wheels. You just need to know that there's an appropriate tool for each job. Actually, there are lots of appropriate tools for each job.

Currently, I am developing a ColdFusion 9 / jQuery / SQL Server intranet that builds external web sites. I am doing it without using a single form tag. And, I am doing it completely in CFSCRIPT. Whoa!

Using jQuery, you don't need forms. You just need inputs. Here's how I create an input in CFSCRIPT.

<cfscript>
Options = "";
for (i = 1; i lte 10; i++) {
  Options = Options & wrapOption("Some choice #i# ", i);
}
SelectBox = wrapSelect(Options, "MySelectID");
writeOutput(SelectBox);
SecretDiv = wrapDiv("", "", "MyDivID");
writeOutput(SecretDiv);
</cfscript>

The user defined functions to create the HTML are in my UDF_Library.cfm file:

// WRAP SELECT
function wrapSelect(SelectContent, Class, ID) {
    LOCAL.SelectContent = ARGUMENTS.SelectContent;
    LOCAL.Properties = "";
    // CLASS
    if (isDefined("ARGUMENTS.Class")) {
        LOCAL.Properties = LOCAL.Properties & " class='#ARGUMENTS.Class#'";
    }
    // ID
    if (isDefined("ARGUMENTS.ID")) {
        LOCAL.Properties = LOCAL.Properties & " id='#ARGUMENTS.ID#'";
    }
    LOCAL.Item = "<select #LOCAL.Properties#>#LOCAL.SelectContent#</select>";
    return LOCAL.Item;
}
// WRAP OPTION
function wrapOption(Content, Value, Selected) {
    LOCAL.Content = ARGUMENTS.Content;
    LOCAL.Properties = " value='#ARGUMENTS.Value#'";
    // SELECTED
    if (isDefined("ARGUMENTS.Selected") and (ARGUMENTS.Selected eq "selected")) {
        LOCAL.Properties = LOCAL.Properties & " selected";
    }
    LOCAL.Item = "<option #LOCAL.Properties#>#LOCAL.Content#</option>";
    return LOCAL.Item;
}
// CREATE DIV
function wrapDiv(Content, Class, ID) {
    LOCAL.Properties = "";
    // CLASS
    if (isDefined("ARGUMENTS.Class")) {
        LOCAL.Properties = LOCAL.Properties & " class='#ARGUMENTS.Class#'";
    }
    // ID
    if (isDefined("ARGUMENTS.ID")) {
        LOCAL.Properties = LOCAL.Properties & " id='#ARGUMENTS.ID#'";
    }
    LOCAL.Item = "<div #LOCAL.Properties#>#ARGUMENTS.Content#</div>";
    return LOCAL.Item;
}

I use jQuery and refer to every element by its class or ID. If you do that, you can submit the data in each element to an ajax call like this:

<script type="text/javascript">
$(document).ready(function() {
$("#MySelectID").change(function() {
   MyID = $("#MySelectID").val();
   $("#MySecretDiv").load("CoolQuery.cfm?UserID"+MyID);
});


});
</script>

The point is, that as long as you are using CFFORM and CFINPUT, you can't do all the really powerful jQuery stuff. But, you need those tags to get started.

2012 is going to be a kick-ass year for the power of ColdFusion and jQuery!!!

Good luck!

魔法少女 2024-11-21 08:25:22

我已经很久没有使用 ColdFusion 的 CFInput 了。我一直在使用 jQuery 验证插件,以便我可以对其他事情执行验证,例如:

  • 元素是否可见? (即,如果不是必需的,则隐藏一个部分,但如果未显示,则消除该要求。)
  • 是否选中了复选框? (即,您选中了“其他”,现在需要填写该空白。)
  • 它是有效的日期/时间值吗? (即,我另外使用 DateJS 库来协助此操作)
  • 执行 ajax 查询以确定用户名是否唯一
  • 输入的 URL 是否有效?
  • 密码 1 与密码 2 自定义规则进行比较
  • 基于组合的

大多数验证规则可以内联添加到类参数中:

<input type="text" name="Name" class="required">
<input type="text" name="Birthdate" class="required date">
<input type="text" name="Email" class="required email">
<input type="text" name="Website" class="url">

我更喜欢使用 jQuery,因为有时我需要将相同的逻辑添加到基于非 ColdFusion 的表单中,但我不这样做必须担心 CFInput 是 ColdFusion-Only 标签这一事实。

以下是有关 jQuery 验证库的更多信息的链接:

http://bassistance.de/ jquery-plugins/jquery-plugin-validation/

I haven't used ColdFusion's CFInput in a long while. I've been using the jQuery Validation plugin so that I can perform validation on other things like:

  • is the element visible? (ie, hide a section if not essential, but eliminate the requirement if not shown.)
  • is a checkbox checked? (ie, you checked "other", now fill-in-the-blank is required.)
  • is it a valid date/time value? (ie, I additionally use the DateJS library to assist in this)
  • perform ajax query to determine if username is unique
  • is the URL entered valid?
  • compare password1 with password2
  • custom rules based on a combination of things

Most validation rules can be added inline to the class parameter:

<input type="text" name="Name" class="required">
<input type="text" name="Birthdate" class="required date">
<input type="text" name="Email" class="required email">
<input type="text" name="Website" class="url">

I prefer to use jQuery because sometimes I need to add this same logic to a non-ColdFusion based form and I don't have to worry about the fact the CFInput is a ColdFusion-Only tag.

Here's a link with more information regarding the jQuery Validation library:

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

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