Skip to main content
Known Participant
March 15, 2013
Question

Binding Form Elements to Query Data

  • March 15, 2013
  • 2 replies
  • 1874 views

Hello,

I have a simple form thatI'm binding query data to so I can populates a cselect box and, based on the selection, populate cfinput boxes. I have the code for this form in a <cfinclude template> and it is working just as designed.

But strangely enough, if I wrap the <cfinclude> code that contains my form in <cfdiv> tags, the binding breaks.

What would be causing that? Any help would be super greatly appreciated.

-Brian

Main Page Code with form:

<cfajaximport tags="cfform,cfdiv">

  <cfdiv>

     <cfinclude template="vehiclelog.cfm">   

  </cfdiv>

CFInclude File:

<cfform name="addmileage" method="post" action="actionpages/addmileage.cfm">

         <table cellpadding="10">

         <tr><td>

          <fieldset>

          <legend>

          <img src="images/service_vehicle.png" alt="Vehicle Log" /> <strong>Vehicle Log </strong> </legend>

        

          <table width="100%" border="0" cellpadding="5">

                  <tr>

                    <td><label>Service Vehicle:</label></td>

                    <td><cfselect queryPosition="below" name="vehicle_name" id="vehicle_name" value="vehicle_name" bind="cfc:cfcs.mileagedata.getData()" bindonload="true" >

                    </cfselect>                    </td>

                  </tr>

                  <tr>

                    <td>Origin:<br />

                      <label></label></td>

                    <td><cfinput name="origin" type="text" /></td>

                  </tr>

                  <tr>

                    <td>Destination:</td>

                    <td><cfinput name="destination" type="text" /></td>

                  </tr>

                  <tr>

                    <td><label>Start Odometer:</label></td>

                    <td><cfinput onFocus="startOdometerCalc();" name="start_odometer" type="text" bind="cfc:cfcs.mileagedata.getDetail({vehicle_name})" bindattribute="value" bindonload="true"/></td>

                  </tr>

                  <tr>

                    <td>End Odometer:</td>

                    <td><cfinput onFocus="startOdometerCalc();" id="end_odometer" name="end_odometer" type="text"  bind="cfc:cfcs.mileagedata.getDetail({vehicle_name})" bindattribute="value" bindonload="true"/></td>

                  </tr>

                  <tr>

                    <td><label>Total mileage:</label></td>

                    <td><cfinput onFocus="startOdometerCalc();" id="total_mileage" name="total_mileage" type="text" /></td>

                  </tr>

                  <tr>

                    <td><label>Expenses:</label></td>

                    <td><cfinput value="0.00" name="expenses" type="text" /></td>

                  </tr>

                  <tr>

                    <td><cfinput type="submit" name="submit" id="submit" value="Submit" /></td>

                    <td> </td>

                  </tr>

                </table>

          </fieldset>

          </td></tr></table></cfform>

CFCS

<!---Service Vehicle Slect Box --->

<cffunction name="getData" access="remote" returntype="query">

    <cfoutput>

    <!--- Function to get data from datasource --->

    <!---Get Service Vehicles --->

    <cfquery name="data" datasource="#datasource#">

    select vehicle_name

    from vehicles

    where active = '1'

    </cfquery>

    </cfoutput>

   

    <!--- Return results --->

    <cfreturn data>

</cffunction>

<cffunction name="getDetail" access="remote" returnType="string">

    <cfargument name="vehicle_name" type="any" required="true">

    <!--- localize function variables --->

    <cfset var dataDetail = "">

    <cfoutput>

    <cfquery name="dataDetail" datasource="#datasource#">

        SELECT mileage

        FROM   vehicles

        <!--- adjust cfsqltype if needed --->

        WHERE vehicle_name = <cfqueryparam value="#ARGUMENTS.vehicle_name#" cfsqltype="cf_sql_varchar">

    </cfquery>

          </cfoutput>

    <cfreturn dataDetail.mileage>

</cffunction></cfcomponent>



This topic has been closed for replies.

2 replies

BKBK
Community Expert
Community Expert
March 17, 2013

There is every reason in this case to use the much simpler <div>, in place of <cfdiv>.

Known Participant
March 15, 2013

I just found something else out. If I remove the <cfform> tags from my template file, which has the form for my DIV, then the bindings work.? Now I'm totally confused.

So then how am I supposed to submit the form in the CFDIV without submiting the form on the main page????

-Brian

Known Participant
March 15, 2013

Ok, found some more info.

When I move my cfdiv out side of the <cfform> tag that is on my main page, everything works as it should. So apparently you cannot have a cfform within a cfform? If so, how do you work around that?

Sorry for the multiple updates. Thanks in advance.

-Brian

Participating Frequently
March 15, 2013

well that sounds like standard HTML-compliance - you can't have nested <form> tags