Skip to main content
Participant
April 10, 2014
Question

<CFINPUT> into <CFFORM>

  • April 10, 2014
  • 2 replies
  • 1237 views

Hello Everybody

I'm getting a very strange situation.

I'm working to migrate a Cold Fusion site from v8 to v10. Into new v10 environment I'm getting an error that is not present into v8 version. The code is the same.

Basically, I have a <cfform> with a dinamic number of <cfinput>. These <cfinput> are generating looping a <CFQUERY>.

In total I have 42 rows.

If I force the limit of the rows to 32, the form is correctly submitted to an "action" destination file that is inserting data into a database.

If I force the limit of the rows to 33, I get an error 500 - "The page you are trying to access can not be displayed. Please try again or notify the administrator". The issue is not related to data, I have already checked for it.

Everytimes the application should update into database ALL rows present on the form.

===============================

THIS IS THE FILE WITH CFFORM

===============================

<CFSET HttpName = "http:" & #Application.RootDir#>

<cfinclude template="..#application.mapping#/includes/algVerifySession.cfm">

<!DOCTYPE html public "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- saved from url=(0036)http://www.elanco.com/meet/meet.html -->

<HTML>

<HEAD>

<TITLE>Average Prices</TITLE>

<CFQUERY name="Get_average_val" datasource="#application.datasource#" username="#application.username#" password="#application.password#">

          SELECT           A.PROFCENT,

          A.VAL,

          SUBSTR(B.DESPRO, 1, 21) AS DESPRO

          FROM           PREZZI_MEDI A, PROFCENTER B

          WHERE          A.PROFCENT = B.PROFCENT

</CFQUERY>

<META content="text/html; charset=windows-1252" http-equiv="Content-Type">

<CFOUTPUT>

<!---MIGRAZIONE ELANCO A CF10--->

<!---<SCRIPT language=Javascript src="#httpname#includes/navscript.js"></SCRIPT>--->

<SCRIPT language=Javascript src="../includes/navscript.js"></SCRIPT>

<!---MIGRAZIONE ELANCO A CF10--->

</CFOUTPUT>

<CFOUTPUT>

<link rel="stylesheet" href= "../includes/newstyle.css" type="text/css">

<SCRIPT type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.js"></SCRIPT>

<SCRIPT type="text/javascript" src="../includes/jquery.paginatetable.js"></SCRIPT>

</CFOUTPUT>

<META content="MSHTML 5.00.2614.3401" name="GENERATOR">

<SCRIPT language="Javascript">function OpenInsert()

                              {

                                        appo_width = 350;

                                        appo_height = 230;

/*                                        if (w == null)                                        */

                                                  var w = window.open("insert.cfm", "DisplayWindow", "Toolbar=No, height=" + appo_height + ", width=" + appo_width + ", resizable=yes");

/*                                        else

                                                  null;

                                                  if (w.closed == false)

                                                            w.close();

                                                            w = window.open("insert.cfm", "DisplayWindow", "Toolbar=No, height=" + appo_height + ", width=" + appo_width + ", resizable=yes"); */

                                        return;

                              }

</SCRIPT>

</HEAD>

<BODY>

<div class="toolbar">

          <div class="tool_title"><h1>Plan Management &raquo; <span>Average Prices Management Tool</span></h1></div>

          <div class="tool_button">

          <a href="javascript: void(0);" onClick="OpenInsert();" class="btn_big_new">Insert</a>

          </div>

          <div class="wrap"></div>

</div>

<CFIF Isdefined("url.ret") and url.ret NEQ "OK">

          <DIV class="Error">Error! Saving failed.</DIV>

</CFIF>

<div class="toolbar">

          <div class="tool_button">

          <table>

                    <tr>

                    <td><a class="button" href="xlsDefault.cfm" >Open Excel</a></td>

                    </tr>

          </table>

          </div>

</div>

<div id="main">

<CFFORM name="update" action="update.cfm?type=update&number=#Get_average_val.RecordCount#" method="post">

          <TABLE id="listvalue" class="tbl_contenuti">

                    <TR>

                              <th>Profit Center</th>

                              <th>Description</th>

                              <th>Average</th>

                    </TR>

                              <tbody>

                                        <CFSET ind = 0>

                                        <CFOUTPUT query="Get_average_val">

                                                  <CFSET ind = ind + 1>

                                                  <CFSET val_name = "VAL_" & ind>

                                                  <CFSET val_name_hid = "VAL_HID_" & ind>

                                                  <CFSET GRP_name_hid = "GRP_HID_" & ind>

                                                  <TR class="body_rows">

                                                            <TD>#PROFCENT#</TD>

                                                            <TD >#DESPRO#</TD>

                                                            <TD align="right">

                                                                      <cfif session.ruolo eq "A">

                                                                                <CFINPUT type="text" name="#val_name#" class="TextLeft" size="14" maxlength="10" value="#VAL#" message="Non hai inserito un valore numerico!" validate="float" >

                                                                      <cfelse>

                                                                                #VAL#

                                                                      </cfif>

                                                                      <INPUT name="#val_name_hid#" value="#VAL#" type="hidden">

                                                                      <INPUT name="#GRP_name_hid#" value="#PROFCENT#" type="hidden">

                                                            </TD>

                                                  </TR>

                                        </CFOUTPUT>

                              </tbody>

                    <TR>

                              <CFOUTPUT>

                                        <TD align="center" colspan="3">

                                                  <cfif session.ruolo eq "A">

                                                            <a href="javascript:document.update.submit();" class="button">Update</a>

                                                            <!---<cfinput type="Submit" name="SubmitForm" value="Submit">--->

                                                  </cfif>

                                        </TD>

                              </CFOUTPUT>

                    </TR>

          </TABLE>

</CFFORM>

    <div class='pager'>

        <a href='#' alt='Previous' class='prevPage'>Prev</a>

        <span class='pageNumbers'></span>

        <span class='currentPage'></span> of <span class='totalPages'></span>

        <a href='#' alt='Next' class='nextPage'>Next</a>

    </div>

    <script>

    $(document).ready(function () {

        $('#listvalue').paginateTable({ rowsPerPage: 10 });

    });

    </script>

</div>

</BODY>

</HTML>

=================================

THIS IS THE FILE THAT IS EXECUTING THE UPDATE (THE ACTION OF THE FORM)

=================================

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<head>

          <title></title>

</head>

</html>

<cfset ret = "OK">

<cfif type EQ "update">

          <cfloop index="ind" from="1" to="#url.number#">

                    <cfset appo_val = Evaluate("val_" & ind)>

                    <cfif appo_val NEQ Evaluate("val_hid_" & ind)>

                              <cfset appo_grp = Evaluate("GRP_HID_" & ind)>

                              <cftransaction action="BEGIN">

                                        <cftry>

                                                  <cfquery name="UpdateAverage" datasource="#application.datasource#" username="#application.username#" password="#application.password#">

                                                            UPDATE PREZZI_MEDI

                                                            SET    VAL = #appo_val#

                                                            WHERE  PROFCENT   = '#appo_grp#'

                                                  </cfquery>

                                                  <cfcatch type="database">

                                                            <cfset ret = "NO">

                                                  </cfcatch>

                                        </cftry>

                                        <CFIF ret EQ "OK">

                                                  <CFTRANSACTION ACTION="COMMIT">

                                        <cfelse>

                                            <CFTRANSACTION ACTION="ROLLBACK">

                                        </cfif>

                              </cftransaction>

                    </cfif>

          </cfloop>

          <cfoutput>

                    <cflocation url="default.cfm?ret=#ret#">

          </cfoutput>

</cfif>

Many Thanks for your help on that.

Best Regards.

M.R.

    This topic has been closed for replies.

    2 replies

    Legend
    April 14, 2014

    The problem you are describing sounds like you're exceeding the maximum POST size limit that patched a security vulnerability. I think in the later CF9 and on to CF10 the default limit was set to 100 fields and some size limit I can't remember. Here is a blog post describing the issue and ways around it: http://blog.cartweaver.com/coldfusion-post-size-limit-causes-400-or-500-error-on-large-forms/. I think there are posts in the forum as well but this is the first useful one that showed up in my google search.

    BKBK
    Community Expert
    Community Expert
    April 14, 2014

    @Steve Sommers

    You are very likely right. In fact, a bell rang the moment I saw your post. Your remark about similar posts in this forum is also spot on.

    BKBK
    Community Expert
    Community Expert
    April 10, 2014

    Nothing springs out. However, you could simplify the code in the action page a lot. The simplication might just clear the mystery.

    Use URL and form scope. Avoid the evaluate function, as it brings in unnecessary complexity.

    Given a recordcount of 42, your current code uses potentially 84 cftransaction tags, that is, 42 'begin' and 42 'commit' or 'rollback'. However, by definition, the queries within a cftransaction tag will either all commit, if successful, or all roll back, if an error occurs in one of them. So, you could in fact use just one cftransaction tag, outside the loop!

    Putting all the above together, we get:

    <cfset ret = "OK">

    <cfif url.type EQ "update">

        <cftransaction>

            <cfloop index="ind" from="1" to="#url.number#">

                <cfset appo_val = form["val_" & ind]>

                <cfif appo_val NEQ form["val_hid_" & ind]>

                    <cfset appo_grp = form["GRP_HID_" & ind]>

                    <cftry>

                    <cfquery name="UpdateAverage" datasource="#application.datasource#" username="#application.username#" password="#application.password#">

                    UPDATE PREZZI_MEDI

                    SET    VAL = #appo_val#

                    WHERE  PROFCENT   = '#appo_grp#'

                    </cfquery>

                    <cfcatch type="database">

                        <cfset ret = "NO">

                    </cfcatch>

                    </cftry>

                </cfif>

            </cfloop>

        </cftransaction>

        <cflocation url="default.cfm?ret=#ret#">

    </cfif>

    Participant
    April 14, 2014

    Hello BKBK

    Many thanks for your message.

    I have applied your suggestions, but unfortunately I'm getting same error.

    Regards.

    M.R.

    BKBK
    Community Expert
    Community Expert
    April 14, 2014

    On second thoughts, the try/catch might be better placed outside the loop, like this:

    <cfset ret = "OK">

    <cftry>

    <cfif url.type EQ "update">

        <cftransaction>

            <cfloop index="ind" from="1" to="#url.number#">

                <cfset appo_val = form["val_" & ind]>

                <cfif appo_val NEQ form["val_hid_" & ind]>

                    <cfset appo_grp = form["GRP_HID_" & ind]>

                    <cfquery name="UpdateAverage" datasource="#application.datasource#" username="#application.username#" password="#application.password#">

                    UPDATE PREZZI_MEDI

                    SET    VAL = #appo_val#

                    WHERE  PROFCENT   = '#appo_grp#'

                    </cfquery>

                </cfif>

            </cfloop>

        </cftransaction>

    </cfif>

    <cfcatch type="database">

        <cfset ret = "NO">

    </cfcatch>

    </cftry>

    <cflocation url="default.cfm?ret=#ret#">