8 Replies Latest reply on Dec 27, 2009 8:29 AM by jeculture

    Bizarre CFIF issue with dynamic form variables? Very strange...

    jeculture

      I can't figure out what I'm doing wrong here.  Here's my code.  Issue explained below.

       

                  <cfquery name="reviewconfigloader" datasource="MOLMS">
                  SELECT *
                  FROM dbo.BaseModel
                  WHERE dbo.BaseModel.AccountID = #molmsAccountID# AND.dbo.BaseModel.basemodelActive = 1
                  </cfquery>

       

       

            <table width="100%" border="0" cellspacing="0" cellpadding="3">
              <cfloop query="reviewconfigloader"><cfif isdefined("form.baseconfig#reviewconfigloader.basemodelID#") AND ("form.baseconfig#reviewconfigloader.basemodelID#") NEQ "" AND ("form.baseconfig#reviewconfigloader.basemodelID#") NEQ 0><cfoutput><tr>
                <td width="40%" bgcolor="##F7F7F7" class="basemodelsub">     #form['baseconfig#reviewconfigloader.basemodelID#']#  #reviewconfigloader.basemodelName# #reviewconfigloader.basemodelSubName#</td>
                <td width="15%" bgcolor="##F7F7F7" class="basemodelsub"><div align="center">x 14 </div></td>
                <td width="15%" bgcolor="##F7F7F7" class="basemodelsub"><div align="center">$486/yr</div></td>
                <td width="15%" bgcolor="##F7F7F7" class="basemodelsub"><div align="center">$1444/yr</div></td>
                <td width="15%" bgcolor="##F7F7F7" class="basemodelsub"><div align="center">$1444/3 yr</div></td>
              </tr></cfoutput></cfif></cfloop>
            </table>

       

       

      What I'm doing here is fairly basic.I'm running a query with a number of configs in it...and then creating a loop to output them.  Ultimately, I only want the configurations that didnt have 0 submitted in the form on the previous page.  Each one of the configs in the config query has a dynamic form variable on the previous page with a quantity tied to it.  I am trying to eliminate all quantities past that aren't 0 (or not eliminate, just not show)...as you can see from the cfif statement.

       

      Here's where it gets weird.  You'll notice I output #form['baseconfig#reviewconfigloader.basemodelID#']#, just for testing, which shows me the quantity as it should.  I ran a test and put in a couple of 1s, 0s, 12s, 6s, etc in the form fields on the previous page.  If this thing worked, it wouldnt show anything for any of the records with their basemodelID value being submitted as 0.  Not the case.  It shows all records.  What is more hilarious is that it outputs perfectly in my test #form['baseconfig#reviewconfigloader.basemodelID#']#, showing the correct numbers entered in the previous form, the 1s, the 0s, etc, tied to each record.  But for whatever reason, the cfif code isn't catching it.

       

      What's even more bizarre...I replaced the cfif ("form.baseconfig#reviewconfigloader.basemodelID#") NEQ 0 with GT 12 (12 was the highest number that I put in the form) and it still showed all records.  Then I put it in as LT 12 and it showed nothing.  I decided  to take it one step further and put it in for GT 1231243242343 (random massive number), which it still showed all of the records.  So somehow, my CFIF statement thinks that  ("form.baseconfig#reviewconfigloader.basemodelID#") is a incredibly large number, although when I output it in the row below, it is the number it should be.

       

      I'm stumped.  Any ideas?  Thanks in advance!!

        • 1. Re: Bizarre CFIF issue with dynamic form variables? Very strange...
          BKBK Adobe Community Professional & MVP

          Try

          <cfif isdefined("form.baseconfig#reviewconfigloader.basemodelID#") AND form.baseconfig#reviewconfigloader.basemodelID# NEQ "" AND form.baseconfig#reviewconfigloader.basemodelID# NEQ 0>

           

          or, perhaps, better

           

          <cfif isdefined("form.baseconfig#reviewconfigloader.basemodelID#") AND form[baseconfig & reviewconfigloader.basemodelID] NEQ "" AND form[baseconfig & reviewconfigloader.basemodelID] NEQ 0>

          • 2. Re: Bizarre CFIF issue with dynamic form variables? Very strange...
            Dan Bracuk Level 5

            To get the correct answer, I suggest a simpler approach.  Start by looping through your form fields and identifying the values you want to display.  Then incorporate those values into the where clause of your query and output all the query results.

             

            I troubleshoot if/else logic problems like this:

             

            if the variable has the expected value

            output yes

            else

            output no and the value and the expected value.

             

            To make your code more efficient, put your cfoutput tag outside the loop so it only has to execute twice.  Also, if the query we see here is the same one you used to generate the form fields, you don't have to run it twice.  Make it a session variable on your form page and do a query of query to narrow down your results based on the form submission.

            1 person found this helpful
            • 3. Re: Bizarre CFIF issue with dynamic form variables? Very strange...
              jeculture Level 1

              hey BKBK, thanks for the try...but this just errors with the # error because the # are taken out of the parenthasis.  So it just bombs.  let me know if you think of anything else though!

              • 4. Re: Bizarre CFIF issue with dynamic form variables? Very strange...
                jeculture Level 1

                Hey Dan...thanks....unfortunately...with the cfif testing, thats kinda what I'm

                doing because I dont have an "expected" value.  My expected value is anything a user inputs thats greater than zero, hence NEQ 0 and NEQ "". The real problem is taht what I'm outputting works and what the cfif clause is seeing is obviously very different.

                 

                As far as your comment about looping out the variables and then setting a query equal to the value in a cfquery, remember...these are form objects and therefore nothing can be tied back to the database.  The result from the code is establishing a form variable (example.... form.basemodel1 (if 1 was the basemodelID from the database query) so it can capture whatever data the user has passed from the previous page in a text input.  So that input could have been 23, it could have been 1053.

                 

                So really the only way to do it is create a query and loop out the variables.... and attach them to form objects (basemodel1, basemodel2, basemodel3 etc where the 1,2 and 3 are the unique ID's for those models in the database), and then look for where those form objects may have been filled in in the previous page by stating IF this form object not equal to 0 or "", output the data.

                 

                Does that make sense?  Thanks for the help guys I'm completely stumped by this.  I've done this a million times with CFIF and I'm really struggling with why this isnt working....

                 

                JE    

                • 5. Re: Bizarre CFIF issue with dynamic form variables? Very strange...
                  Dan Bracuk Level 5

                  Regarding:

                  So really the only way to do it is create a query and loop out the variables....

                   

                  Not really.

                   

                  List_of_ids = "";

                  <cfloop list = "#form.fieldnames#" index = "ThisField">

                  <cfscript>

                  if (left(ThisField, 9) is "basemodel" and form[ThisField] gt 0) {

                  ThisID = RemoveChars(ThisField, 1, 9);

                  List_of_ids = ListAppend(List_of_ids, ThisID)

                  }

                   

                  closing tags

                   

                  then if your listlength is greater than 0, run a query that includes

                   

                  where TheIDField in (#List_of_ids#)

                  1 person found this helpful
                  • 6. Re: Bizarre CFIF issue with dynamic form variables? Very strange...
                    BKBK Adobe Community Professional & MVP
                    hey BKBK, thanks for the try...but this just errors with the # error because the # are taken out of the parenthasis.  So it just bombs.  let me know if you think of anything else though!

                    Sorry about that, Jeculture. The Xmas factor.

                     

                    I rolled it out without checking. What it should have said is:

                     

                    <cfif isdefined("form.baseconfig#reviewconfigloader.basemodelID#") AND form["baseconfig#reviewconfigloader.basemodelID#"] NEQ "" AND form["baseconfig#reviewconfigloader.basemodelID#"] NEQ 0>

                     

                    or

                     

                    <cfif isdefined("form.baseconfig#reviewconfigloader.basemodelID#") AND form["baseconfig" & reviewconfigloader.basemodelID] NEQ "" AND form["baseconfig" & reviewconfigloader.basemodelID] NEQ 0>

                    • 7. Re: Bizarre CFIF issue with dynamic form variables? Very strange...
                      jeculture Level 1

                      Thanks a ton guys!!  BKBK the second solution works...although i could have swore I already used the form[] solution in the cfif!!  I must have had a sequence issue or something...sometimes it just takes an outside eye.

                       

                      The cfscript solution also worked, thanks a ton for that as well!  I'm trying to keep it simple as possible for trouble shooting purposes, but you've both been awesome with the quick responses.  Have a good day guys!

                      JE