views:

488

answers:

1

My apologies if I worded the title wrong.

I've got a large table with multiple input boxes and need to get the values of the internal cells.

I am able to get the dates, gas amounts/totals, and the totals, but not the rest.

I need still to be able to get every other input box's value.

I am not too sure where to go with this one, but I think you need to two names.

This form is submitted to a pdf where I get the values.



The form code:

<cfloop from="1" to="#ArrayLen(labels)#" index="r">
    <tr>
     <td class="labels"><cfif ArrayIsDefined(labels,r) AND labels[r] NEQ "Open1">
       <cfif labels[r] EQ "Open">
        <input type="text" name="descript#r#" class="description" value="Enter text here" style="width:auto;" />
        <cfelse>
        #labels[r]#
       </cfif>
      </cfif></td>
     <cfloop from="1" to="7" index="i">
      <td id="Day#i#" class="row#r# col#i#"><cfif r EQ 1>
        #Left(DayOfWeekAsString(i),3)#
        <cfelse>
        <cfif r EQ 2>
         <input type="text" class="date-mask" name="dates#i#" />
         <cfelse>
         <input type="text" 
           <cfif labels[r] EQ "Personal Car: Mileage ##"> id="gasamount#i#" <cfelseif labels[r] EQ "Personal Car: Mileage $">id="gasmoney#i#"  </cfif><cfif labels[r] EQ "Daily Totals">id="dailytotals#i#"</cfif>
            class="<cfif labels[r] EQ "Personal Car: Mileage ##">gasamount<cfelse><cfif labels[r] NEQ "Daily Totals">C#i#</cfif></cfif>
            <cfif labels[r] EQ "Personal Car: Mileage $">gasmoney<cfelse>calc R#r#</cfif>
            <cfif labels[r] EQ "Daily Totals">ttlC#i#</cfif>" 
            <cfif labels[r] EQ "Daily Totals" OR labels[r] EQ "Personal Car: Mileage $" OR labels[r] EQ "Open1">readonly="readonly"</cfif> 
            name="<cfif labels[r] NEQ "Personal Car: Mileage ##" AND labels[r] NEQ "Personal Car: Mileage $" AND labels[r] NEQ "Dates:" AND labels[r] NEQ "Open1" AND labels[r] NEQ "Daily Totals">R#r# C#i#</cfif>
            <cfif labels[r] EQ "Personal Car: Mileage ##">gasamt#i#</cfif>
            <cfif labels[r] EQ "Daily Totals">celltotals#i#</cfif>
            <cfif labels[r] EQ "Personal Car: Mileage $">gastot#i#</cfif>"
              />
        </cfif>
       </cfif></td>
     </cfloop>
     <td class="totals"><cfif r EQ 1>
       Total
       <cfelse>
       <input type="text" id="totals" class="ttlR#r#" name="totals#r#" readonly="readonly" />
      </cfif></td>
    </tr>
</cfloop>


And the PDF Code:

<cfloop from="1" to="#ArrayLen(labels)#" index="r">
    <tr>
     <td class="labels"><cfif ArrayIsDefined(labels,r) AND labels[r] NEQ "Open1">
       <cfif labels[r] EQ "Open">
        <span>#form['descript' & r]#</span>
        <cfelse>
        #labels[r]#
       </cfif>
      </cfif></td>
     <cfloop from="1" to="7" index="i">
      <td id="Day" class="row#r# col#i#"><cfif r EQ 1>
        #Left(DayOfWeekAsString(i),3)#
        <cfelse>
        <cfif labels[r] EQ "Date:">
         <span style="width:60px;">#form['dates' & i]#</span>
         <cfelse>
         <span style="width:60px;">
         <cfif labels[r] EQ "Personal Car: Mileage ##">
          #form[" " & 'gasamt' & i & " "]#
         </cfif>
         <cfif labels[r] EQ "Personal Car: Mileage $">
          #form[" " & 'gastot' & i]#
         </cfif>
         <cfif labels[r] EQ "Daily Totals">
          #form[" " & 'celltotals' & i & " "]#
         </cfif>
         <cfif labels[r] NEQ "Personal Car: Mileage ##" AND labels[r] NEQ "Personal Car: Mileage ##" AND labels[r] NEQ "Dates:" AND labels[r] NEQ "Open1" AND labels[r] NEQ "Daily Totals">
          #form['R' & r & " "]#
         </cfif>
        </cfif>
       </cfif>
       </span></td>
     </cfloop>
     <td class="totals" style="width: 60px;"><cfif r EQ 1>
       Total
       <cfelse>
       <span style="text-align:right;">#form['R' & r & " " & 'C' & i & " "]#</span>
      </cfif></td>
    </tr>
</cfloop>


I've added spaces in those objects because the names all seem to have spaces in different places, yet there is none in the code.

I have an error when you submit the page at the moment because of how I'm trying to reference the form elements.

Thanks in advance for anytime you spend trying to help out.

A: 

I don't know if this is exactly the problem, but...

This snippet of code:

<cfif labels[r] NEQ "Personal Car: Mileage ##" 
    AND labels[r] NEQ "Personal Car: Mileage $" 
    AND labels[r] NEQ "Dates:" 
    AND labels[r] NEQ "Open1" 
    AND labels[r] NEQ "Daily Totals">R#r# C#i#</cfif>

Is going to give you a form variable with a space in it. You can probably get away with that with just HTML, but valid ColdFusion variable names cannot contain spaces. You can probably get away with it using bracket notation, but why risk it?

Have you used CFDUMP to examine that your form is returning the values you're expecting?

edit: Heck, almost all of your input elements are going to have spaces in their names because of whitespace. That's going to cause havoc on your action page and your JavaScript.

Here's an interim update to your first code block. It's not perfect, but it doesn't change the logic and should get you better formatted HTML in the end.

<cfloop from="1" to="#ArrayLen(labels)#" index="r">
<tr>
    <td class="labels">
        <cfif ArrayIsDefined(labels,r) AND labels[r] NEQ "Open1">
            <cfif labels[r] EQ "Open">
                <input type="text" name="descript#r#" class="description" value="Enter text here" style="width:auto;" />
            <cfelse>
                #labels[r]#
            </cfif>
        </cfif>
    </td>
    <cfloop from="1" to="7" index="i">
        <td id="Day#i#" class="row#r# col#i#">
            <cfif r EQ 1>
                #Left(DayOfWeekAsString(i),3)#
            <cfelse>
                <cfif r EQ 2>
                    <input type="text" class="date-mask" name="dates#i#" />
                <cfelse>
                    <cfset tempid="" />
                    <cfif labels[r] EQ "Personal Car: Mileage ##"> 
                        <cfset tempid="gasamount#i#" />
                    <cfelseif labels[r] EQ "Personal Car: Mileage $">
                        <cfset tempid="gasmoney#i#" />
                    <cfelseif labels[r] EQ "Daily Totals">
                        <cfset tempid="dailytotals#i#" />
                    </cfif>

                    <cfset tempclass="" />
                    <cfif labels[r] EQ "Personal Car: Mileage ##">
                        <cfset tempclass="gasamount" />
                    <cfelse>
                        <cfif labels[r] NEQ "Daily Totals">
                            <cfset tempclass="C#i#" />
                        </cfif>
                    </cfif>
                    <cfif labels[r] EQ "Personal Car: Mileage $">
                        <cfset tempclass="gasmoney" />
                    <cfelse>
                        <cfset tempclass="calc R#r#" />
                    </cfif>
                    <cfif labels[r] EQ "Daily Totals">
                        <cfset tempclass="ttlC#i#" />
                    </cfif>

                    <cfset tempreadonly="" />
                    <cfif labels[r] EQ "Daily Totals" OR labels[r] EQ "Personal Car: Mileage $" OR labels[r] EQ "Open1">
                        <cfset tempreadonly="readonly=""readonly""" />
                    </cfif> 

                    <cfset tempname="" />
                    <cfif labels[r] NEQ "Personal Car: Mileage ##" AND labels[r] NEQ "Personal Car: Mileage $" AND labels[r] NEQ "Dates:" AND labels[r] NEQ "Open1" AND labels[r] NEQ "Daily Totals">
                        <cfset tempname="R#r# C#i#" />
                    </cfif>
                    <cfif labels[r] EQ "Personal Car: Mileage ##">
                        <cfset tempname="gasamt#i#" />
                    </cfif>
                    <cfif labels[r] EQ "Daily Totals">
                        <cfset tempname="celltotals#i#" />
                    </cfif>
                    <cfif labels[r] EQ "Personal Car: Mileage $">
                        <cfset tempname="gastot#i#" />
                    </cfif>
                    <input type="text" id="#tempid#" class="#tempclass#" #tempreadonly# name="#tempname#" />
                </cfif>
            </cfif>
        </td>
    </cfloop>
    <td class="totals">
        <cfif r EQ 1>
            Total
        <cfelse>
            <input type="text" id="totals" class="ttlR#r#" name="totals#r#" readonly="readonly" />
        </cfif>
    </td>
</tr>
</cfloop>

While you can mix CFML with your HTML output, it can quickly spiral out of control. As a general rule, you want to do as much processing and decision-making with pure CFML, then just output a few variables.

Al Everett
That doesn't fix anything, but it does make it a bit clear.
Michael Stone
I figured as much. The way you've put the code together really makes it hard to troubleshoot, as you've found.
Al Everett