Coldfusion 将表单值传递给cfc

Coldfusion 将表单值传递给cfc,coldfusion,Coldfusion,我有一个cfc,其中一个函数返回一个查询,其中包含一个表中显示的员工列表。我在页面上有一个排序表单,单击列标题时,需要根据单击的列对数据进行排序。现在,只要所有的查询都在页面上,我就可以完成所有的工作。我正在尝试将查询转移到cfc。我确信我在这里遗漏了一些基本的东西。有人能告诉我如何从列标题的cfc onclick中获得排序结果吗 <script> function submitformnow(x){ if (document.form.show.value

我有一个cfc,其中一个函数返回一个查询,其中包含一个表中显示的员工列表。我在页面上有一个排序表单,单击列标题时,需要根据单击的列对数据进行排序。现在,只要所有的查询都在页面上,我就可以完成所有的工作。我正在尝试将查询转移到cfc。我确信我在这里遗漏了一些基本的东西。有人能告诉我如何从列标题的cfc onclick中获得排序结果吗

 <script>
      function submitformnow(x){
      if (document.form.show.value == "DESC")
       {$('input[name=show]').val('ASC');}
          else{ $('input[name=show]').val('DESC');}
           $('input[name=order_by]').val(x);
           document.form.submit();
          }
    </script>

 <cffunction name="getemps" access="public" output="false" returntype="query">
    <cfargument name="emp_id" type="numeric" default="#variables.emp_id#" />
    <cfargument name="order_by" default="#variables.order_by#" type="string" required="no">
    <cfargument name="show" default="#variables.show#" type="string" required="no">

    <cfquery name="qemps" datasource="test">
        select * from emps
      <cfif len(trim(arguments.order_by)) and arguments.order_by NEQ '' and len(trim(arguments.show)) and arguments.show NEQ '' >
       ORDER BY #arguments.order_by# #arguments.show#
       </cfif>
    </cfquery>
</cffunction>
<cfset employee= new cfcs.employees() />
<cfset getemps = employee.getemps(emp_id,order_by,show) />//order_by, show are the form field here//
试一试

还要记住你的表格。变量,然后再引用它们以确保它们存在

<cfparam name="form.emp_id" default=0>
<cfparam name="form.order_by" default="">
<cfparam name="form.show" default="ASC">
<cfset getemps = employee.getemps(form.emp_id,form.order_by,form.show)>

您正在寻找的可能是通过datatables之类的前端工具更好地处理的。该工具看起来像什么?员工ID是表单字段吗?您应该在查询中验证arguments.order\u by和arguments.show。实际上,它很容易受到SQL注入的攻击,因为它们是直接从表单中传入的。
<cfparam name="form.emp_id" default=0>
<cfparam name="form.order_by" default="">
<cfparam name="form.show" default="ASC">
<cfset getemps = employee.getemps(form.emp_id,form.order_by,form.show)>