17 Replies Latest reply on Mar 31, 2014 3:17 PM by iccsi

    Assign cfinput checkbox value

    iccsi Level 1

      I have following code to assign value from my stored procedures.

      The text cfinput works to get value from stored procedure, but check box does not get value.

      The check box value return to 1, but check box does not check.

       

      I would like to know are there any way to assign a stored procedure value to check box.

       

      Your help and information is great appreciated,

       

      Regards,

       

      iccsi,

       

       

      <td><cfinput type="checkbox" name="Mychk" id="Mychk" value="#MySP.MyCheckValue#"></td>

      <td><cfinput type="text" name="Mytxt" id="Mytxt" value="#MySP.MyTextValue#"></td>

        • 1. Re: Assign cfinput checkbox value
          Dave Ferguson Level 3

          First off... don't use cfinput.   Just use standard form fields. As to the checkbox being checked. Unless you set the checked attribute of the input it won't load as checked.

           

          <input type="checkbox" name="Mychk" id="Mychk" value="#MySP.MyCheckValue#" <cfif len(mysp.mycheckvalue)>checked="checked"</cfif>>

           

          <input type="text" name="Mytxt" id="Mytxt" value="#MySP.MyTextValue#">

           

           

          HTH,

           

          --Dave

          • 2. Re: Assign cfinput checkbox value
            iccsi Level 1

            Thanks for the informaiton and help,

            I thouht that CFINPUT has more benefits and properties to use than standard controls,

            Are there any issue with CFINPUT?

             

            Should I not use all CFINPUT for all the forms like text, textararea, CFSELECT?

             

            Thanks again for helping,

            Regards,

             

            Iccsi,

            • 3. Re: Assign cfinput checkbox value
              Dave Ferguson Level 3

              I would avoid using the cfinput tags all together.  They just add unncessary bloat to the ui and make things more difficult in the long run.

               

               

              --Dave

              • 4. Re: Assign cfinput checkbox value
                BKBK Adobe Community Professional & MVP

                iccsi wrote:

                 

                I have following code to assign value from my stored procedures.

                The text cfinput works to get value from stored procedure, but check box does not get value.

                The check box value return to 1, but check box does not check.

                 

                I would like to know are there any way to assign a stored procedure value to check box.

                ...

                <td><cfinput type="checkbox" name="Mychk" id="Mychk" value="#MySP.MyCheckValue#"></td>

                Yes, you may assign a value like that to a checkbox! But it works differently from how you expect. Run the following test, and you will notice the following main points:

                 

                1) If you fail to tick the checkbox, ColdFusion will omit the checkbox field from the submitted form scope. No checkbox field, no value.

                 

                2) If you assign a value to the checkbox field, which you've done here, that value will be stored in the checkbox field when the form is submitted. In view of 1), the assumption is that the checkbox is checked before submission. In your example, the value #MySP.MyCheckValue# will be stored in the variable form.Mychk.

                 

                3) The state of the checkbox, that is, whether it is checked or not, is independent of its value attribute. The state is determined by the 'checked' attribute.

                 

                <cfdump var="#form#">

                 

                <cfform name="myForm" method="post">

                <cfif isdefined("form.mychk") and form.mychk is 'aaa'>

                         <!--- 'Checked' is the attribute that determine the state of a checkbox, not value --->

                    <cfinput type="checkbox" name="Mychk" id="Mychk" value="blah blah blah" checked="yes">

                <cfelse>

                    <cfinput type="checkbox" name="Mychk" id="Mychk" value="blah blah blah">

                </cfif>

                <cfinput type="text" name="Mytxt" id="Mytxt" value="some text"><br>

                <cfinput name="sbmt" type="submit" value="send">

                </cfform>

                • 5. Re: Assign cfinput checkbox value
                  Dave Ferguson Level 3

                  Any code examples using cfform are bad examples IMO.  Please use standard html forms as the cf forms give you nothing but pain and grief.

                   

                  <cfdump var="#form#">

                   

                  <cfform name="myForm" method="post">

                  <cfif isdefined("form.mychk") and form.mychk is 'aaa'>

                           <!--- 'Checked' is the attribute that determine the state of a checkbox, not value --->

                      <cfinput type="checkbox" name="Mychk" id="Mychk" value="blah blah blah" checked="yes">

                  <cfelse>

                      <cfinput type="checkbox" name="Mychk" id="Mychk" value="blah blah blah">

                  </cfif>

                  <cfinput type="text" name="Mytxt" id="Mytxt" value="some text"><br>

                  <cfinput name="sbmt" type="submit" value="send">

                  </cfform>

                   

                  Also, to clarify.  An unchecked checkbox is not omitted by CF.  It is actually omitted by the browser when the form is submitted.  This is completely out of CF's control.

                   

                   

                  1) If you fail to tick the checkbox, ColdFusion will omit the checkbox field from the submitted form scope. No checkbox field, no value.

                   

                   

                  --Dave

                  • 6. Re: Assign cfinput checkbox value
                    BKBK Adobe Community Professional & MVP

                    fergusondj wrote:

                     

                    Any code examples using cfform are bad examples IMO.  Please use standard html forms as the cf forms give you nothing but pain and grief.

                    As you say, that is your opinion, which you are entitled to. In my opinion, one cannot make such blanket generalizations about cfform. Yes, there are situations in which they cause grief, but there are also situations in which they are quite useful, especially to those starting out in ColdFusion.

                     

                    Also, to clarify.  An unchecked checkbox is not omitted by CF.  It is actually omitted by the browser when the form is submitted.  This is completely out of CF's control.

                    You misinterpret what I said. I did not say an unchecked checkbox is omitted by ColdFusion. I will repeat what I said: "If you fail to tick the checkbox, ColdFusion will omit the checkbox field from the submitted form scope.". That is a true statement.

                    • 7. Re: Assign cfinput checkbox value
                      BKBK Adobe Community Professional & MVP

                      Correction to the test code:

                       

                      <cfdump var="#form#">

                       

                      <cfform name="myForm" method="post">

                      <cfif isdefined("form.mychk") and form.mychk is 'blah blah blah'>

                               <!--- 'Checked' is the attribute that determine the state of a checkbox, not value --->

                          <cfinput type="checkbox" name="Mychk" id="Mychk" value="blah blah blah" checked="yes">

                      <cfelse>

                          <cfinput type="checkbox" name="Mychk" id="Mychk" value="blah blah blah">

                      </cfif>

                      <cfinput type="text" name="Mytxt" id="Mytxt" value="some text"><br>

                      <cfinput name="sbmt" type="submit" value="send">

                      </cfform>

                      • 8. Re: Assign cfinput checkbox value
                        iccsi Level 1

                        Thanks for your information and help,

                         

                        Regards,

                         

                         

                        Iccsi,

                        • 9. Re: Assign cfinput checkbox value
                          Dave Ferguson Level 3

                          Just a couple things...

                           

                          First, you are completely wrong here.  As I stated before ColdFusion will not omit anything from the form scope.  It has no control over what the browsers sends to the server.  The form field omission is done by the browser.  There is nothing for CF to omit as the field would not be submitted by the browser.

                           

                          Next, again you are completely wrong about the use of any of the cf ui tags (cfform, cfgrid, cflayout, etc.. ).  These should not be used by someone learning CF, or anyone else for that matter.  They don't teach you CF, the teach you how to do crappy UI that will not translate over to any other technology.  A new developer is better off learning JS and how to build forms properly so that knowledge can translate to other languages.

                           

                          If you were to look in StackOverflow you would people consistently trying to get people to not use the UI tags.  Anytime someone posts a question about any of the UI tags, one of the first comments are generally..  "stop using the ui tags".

                           

                          You might want to read this blog post...

                          http://www.raymondcamden.com/index.cfm/2014/1/23/Im-not-going-to-tell-you-to-stop-using-Co ldFusion-UI-tags-anymore

                           

                          Then check out..

                          https://github.com/cfjedimaster/ColdFusion-UI-the-Right-Way

                           

                           

                          --Dave

                          • 10. Re: Assign cfinput checkbox value
                            BKBK Adobe Community Professional & MVP

                            fergusondj wrote:

                             

                            First, you are completely wrong here.  As I stated before ColdFusion will not omit anything from the form scope.  It has no control over what the browsers sends to the server.  The form field omission is done by the browser.  There is nothing for CF to omit as the field would not be submitted by the browser.

                            I hope you can see that your arguments have leaned so far on misunderstandings. This time you make a shift within 3 sentences from 'scope', the word I used, to 'field'. The shift is subtle, but makes all the difference. The form scope I talk about pertains to ColdFusion, not to the browser.

                             

                            To illustrate with a concrete example, suppose the form in question has a checkbox named chkbx. Suppose further that you submit the form without checking the checkbox. Then, on the CFM action page, ColdFusion will omit the key chkbx from the form structure. This is simply a statement of fact. It is true, whether or not the browser sends the field to the server.

                             

                            Next, again you are completely wrong about the use of any of the cf ui tags (cfform, cfgrid, cflayout, etc.. ).  These should not be used by someone learning CF, or anyone else for that matter.  They don't teach you CF, the teach you how to do crappy UI that will not translate over to any other technology.  A new developer is better off learning JS and how to build forms properly so that knowledge can translate to other languages.

                             

                            If you were to look in StackOverflow you would people consistently trying to get people to not use the UI tags.  Anytime someone posts a question about any of the UI tags, one of the first comments are generally..  "stop using the ui tags".

                             

                            You might want to read this blog post...

                            http://www.raymondcamden.com/index.cfm/2014/1/23/Im-not-going-to-tell- you-to-stop-using-ColdFusion-UI-tags-anymore

                             

                            Then check out..

                            https://github.com/cfjedimaster/ColdFusion-UI-the-Right-Way

                             

                            Once again, you claim I am wrong when I mention another statement of fact. I have been around for a bit as a ColdFusion developer and am aware of the the issues regarding the UI tags. In fact, I myself have had to resort over the years to alternative solutions like Dojo, Ext and JQuery. However, this isn't about me.

                             

                            Many colleagues use - and, if recent history is anything to go by, will in the near future continue to use - ColdFusion's UI tags. Especially, a lot of developers starting out in ColdFusion consider them simple, versatile solutions to their problems. Rightly or wrongly. That is simply a fact of life.

                             

                            Naturally, I agree with you that more experienced developers owe it to the community to sound a note of warning about the issues that may arise with the UI tags. However, I do believe that such advice will be more effective if delivered with a tickle rather than a punch.

                             

                            In my opinion, there is a psychological component to this. People invest time to learn ColdFusion, and good money to acquire a license. They want to believe in all the goodies the platform promises to deliver. They would hate and resist you if you attempted to spoil the dream for them. Ironically, your reference to Raymond Camden actually says something similar.

                             

                            This reminds me of one of the best books on strategy I ever read, David Maister's Strategy and The Fat Smoker. Why would an intelligent man, a professor at Harvard, no less, continue to smoke, put on weight and avoid exercise even after his physician warns him of the impending danger to his heart? The answer is trivial and universal. It has little to do with rationality. The professor or the ColdFusion developer, like most human beings, prefers the easy life, wants to believe things will work out somehow today, and puts off difficult changes until tomorrow.

                            • 11. Re: Assign cfinput checkbox value
                              Scott Stroz Level 1

                              To illustrate with a concrete example, suppose the form in question has a checkbox named chkbx. Suppose further that you submit the form without checking the checkbox. Then, on the CFM action page, ColdFusion will omit the key chkbx from the form structure. This is simply a statement of fact. It is true, whether or not the browser sends the field to the server.

                              You are incorrect, sir.

                               

                              If you have a checkbox that is not checked, and submit the form, the form field is NEVER sent to ColdFusion, therefore, there is nothing for ColdFusion to 'omit' in the form 'structure' (or what the rest of us call the 'form scope').

                               

                              Your lack of basic understanding of how form submission works concerns me for someone who has a '+++' rating.

                              • 12. Re: Assign cfinput checkbox value
                                BKBK Adobe Community Professional & MVP

                                Scott Stroz wrote:

                                 

                                To illustrate with a concrete example, suppose the form in question has a checkbox named chkbx. Suppose further that you submit the form without checking the checkbox. Then, on the CFM action page, ColdFusion will omit the key chkbx from the form structure. This is simply a statement of fact. It is true, whether or not the browser sends the field to the server.

                                You are incorrect, sir.

                                 

                                If you have a checkbox that is not checked, and submit the form, the form field is NEVER sent to ColdFusion, therefore, there is nothing for ColdFusion to 'omit' in the form 'structure' (or what the rest of us call the 'form scope').

                                 

                                Your lack of basic understanding of how form submission works concerns me for someone who has a '+++' rating.

                                You, sir, have to be sure of your stuff before throwing insults about. Nowhere do I suggest that a browser sends an unchecked checkbox field to ColdFusion. Please sharpen up your thinking. Apparently, the part of my arguments you fail to understand has little to do with the technicalities of form submission and more to do with language and logic.

                                 

                                One meaning of the word omit is not include. This does not necessarily mean that that which is omitted was available for inclusion in the first place! That is the context in which I used the word.

                                 

                                As I said in my last post, the form scope omits the checkbox field, whether or not the browser sends the field to the server. It requires just modest mental power to pick up the scent of logic.

                                 

                                You should reread what I said, in full. If anything, it actually implicitly hints at what you both have been trying to point out.

                                 

                                BKBK wrote:

                                 

                                1) If you fail to tick the checkbox, ColdFusion will omit the checkbox field from the submitted form scope. No checkbox field, no value.

                                 

                                2) If you assign a value to the checkbox field, which you've done here, that value will be stored in the checkbox field when the form is submitted. In view of 1), the assumption is that the checkbox is checked before submission. In your example, the value #MySP.MyCheckValue# will be stored in the variable form.Mychk.

                                 

                                3) The state of the checkbox, that is, whether it is checked or not, is independent of its value attribute. The state is determined by the 'checked' attribute.

                                • 13. Re: Assign cfinput checkbox value
                                  BKBK Adobe Community Professional & MVP

                                  fergusondj wrote:

                                   

                                  First off... don't use cfinput.   Just use standard form fields. As to the checkbox being checked. Unless you set the checked attribute of the input it won't load as checked.

                                   

                                  <input type="checkbox" name="Mychk" id="Mychk" value="#MySP.MyCheckValue#" <cfif len(mysp.mycheckvalue)>checked="checked"</cfif>>

                                   

                                  <input type="text" name="Mytxt" id="Mytxt" value="#MySP.MyTextValue#">

                                  It is still possible to use <input> in <cfform>. So I should like to add that what you apparently mean is: don't use cfform.

                                  • 14. Re: Assign cfinput checkbox value
                                    Scott Stroz Level 1

                                    When you say the form scope in ColdFusion 'omits' an unchecked checkbox regardless of whether the form field was passed to the server or not, the implication is that the 'omission' is on the part of ColdFusion - which is not the case. The form scope contains only the values that were submitted via  POST operation and any values that are manually added to the form scope in the code.

                                     

                                    Semantics? Maybe. But, logic would dictate that it is more accurate to say that the browser does not pass unchecked checkboxes to the server. This has nothing to do with ColdFusion, or the form scope, and everythign to do with how browsers work - regardless of the server side technology.

                                    • 15. Re: Assign cfinput checkbox value
                                      BKBK Adobe Community Professional & MVP

                                      Scott Stroz wrote:

                                       

                                      When you say the form scope in ColdFusion 'omits' an unchecked checkbox regardless of whether the form field was passed to the server or not, the implication is that the 'omission' is on the part of ColdFusion - which is not the case.

                                      Again, by 'omit' I meant 'not include'. In other words, unchecked checkbox at the client implies non-inclusion of nameOfCheckBoxField in ColdFusion's form struct. Simple. 'Omit' may be used in that context. I went further and explained, for good measure.

                                       

                                      Semantics? Maybe. But, logic would dictate that it is more accurate to say that the browser does not pass unchecked checkboxes to the server. This has nothing to do with ColdFusion, or the form scope, and everythign to do with how browsers work - regardless of the server side technology.

                                      Now the beginning of another palaver about semantics, accuracy, and the rest of it. If you, like Fergusondj, are burning to talk to the forum about browsers and form fields, then do so by all means. But it is rude to force words into my mouth just to enable you to strut your MVP stuff. Much like planting ganja on a man to be able to catch him at customs.

                                       

                                      I should hope I am entitled to say what I wish to say, how I wish to say it. I am the author and I have spoken as I wished to speak. Where there seemed to be a misunderstanding, I made the effort to explain. Let's call it a difference of opinion and move on, shall we? 

                                      • 16. Re: Assign cfinput checkbox value
                                        BKBK Adobe Community Professional & MVP

                                        iccsi wrote:

                                         

                                        The text cfinput works to get value from stored procedure, but check box does not get value.

                                        The check box value return to 1, but check box does not check.

                                        ...

                                        <cfinput type="checkbox" name="Mychk" id="Mychk" value="#MySP.MyCheckValue#">

                                        @Iccsi

                                         

                                        I hope you could find your answer amid all the distraction. The value of the checkbox, #MySP.MyCheckValue# in this case, is not what determines whether the checkbox will be checked. What ensures the checkbox will be checked is the checked attribute. That is

                                         

                                        <cfinput type="checkbox" name="Mychk" id="Mychk" value="#MySP.MyCheckValue#" checked>

                                         

                                        or

                                         

                                        <cfinput type="checkbox" name="Mychk" id="Mychk" value="#MySP.MyCheckValue#" checked="yes">

                                        • 17. Re: Assign cfinput checkbox value
                                          iccsi Level 1

                                          Thanks a million for the information and help,

                                           

                                           

                                          Regards,

                                           

                                          Iccsi,