16 Replies Latest reply: May 14, 2012 6:26 AM by goodychurro1 RSS

    Bind ahref link (like cfinput) in cfform

    goodychurro1 Community Member

      Hi all

      How can I output this value (that it correctly shown in a cfinput), also as a link? I am using cfform. As far as I can gather by googling I may have to use cfdiv or cflayout? Thank you

       

      CFINPUT:

      <cfinput type="text" name="COMPANY" label="Company" required="yes" width="200"
              bind="{UsersGrid.dataProvider[UsersGrid.selectedIndex]['COMPANY']}"
              onChange="UsersGrid.dataProvider.editField(UsersGrid.selectedIndex,

      'COMPANY', COMPANY.text);">

       

      MY ATTEMPT:

      <a href="mysite.com?company=<cfoutput>#company#</cfoutput>">Company link</a>

        • 1. Re: Bind ahref link (like cfinput) in cfform
          BKBK CommunityMVP

          Something like

          <cfdiv id = "companyDiv" bind="<a href="""mysite.com?company=+{dt}+"">Company link</a>" />

          • 2. Re: Bind ahref link (like cfinput) in cfform
            goodychurro1 Community Member

            Thanks for the reply BKBK I get this error:

             

             

             

            Invalid token . found on line 129 at column 49. 
             
            The CFML compiler was processing: 

            The tag attribute mysite, on line 129, column 43. 
            A cfdiv tag beginning on line 129, column 2.


            The error occurred in member_welcome.cfm: line 129

            127 :  128 : </cfformgroup>  129 : <cfdiv id = "companyDiv" bind="<a href="""mysite.com?company=+{dt}+"">Company link</a>" />  130 :  131 : <cfformgroup type="horizontal">  

            • 3. Re: Bind ahref link (like cfinput) in cfform
              BKBK CommunityMVP

              My bad, I think. There should perhaps be 2 quotes after href=, not 3.

              • 4. Re: Bind ahref link (like cfinput) in cfform
                goodychurro1 Community Member

                Thanks bkbk that sorted out that error but now I get a js alert error:

                "Bind failed, element not found: dt"

                I imagine this is because I have not selected a company yet so it has no data to bind, but that is the same case in the cfinputs and they don't thorw an error:

                CFINPUT:

                <cfinput type="text" name="COMPANY" label="Company" required="yes" width="200"
                bind="{UsersGrid.dataProvider[UsersGrid.selectedIndex]['COMPANY']}"
                onChange="UsersGrid.dataProvider.editField(UsersGrid.selectedIndex,

                'COMPANY', COMPANY.text);">

                • 5. Re: Bind ahref link (like cfinput) in cfform
                  BKBK CommunityMVP

                  goodychurro1 wrote:

                   

                  Thanks bkbk that sorted out that error but now I get a js alert error:

                  "Bind failed, element not found: dt"

                  I imagine this is because I have not selected a company yet so it has no data to bind, but that is the same case in the cfinputs and they don't thorw an error:

                  You should have just filled in the field name in place of my 'dt'! Something like this

                   

                  <cfdiv id = "companyDiv" bind="<a href=""mysite.com?company=+{company}+"">Company link</a>" />

                  • 6. Re: Bind ahref link (like cfinput) in cfform
                    goodychurro1 Community Member

                    Thanks bkbk, I tried that and get two errors:

                     

                    1)Bind failed element not found: COMPANY

                    Bind failed element not found: companyDIV

                     

                    Code:  <cfdiv id = "companyDiv" bind="<a href=""mysite.com?COMPANY=+{COMPANY}+"">Company link</a>" />

                     

                    2) I also tried using the code in the cfinput to see if it would work but I get an error:

                     

                    Error parsing bind expression at character 29:{ in Company link

                     

                    Code:

                    <cfdiv id = "companyDiv" bind="<a href=""mysite.com?COMPANY=+{UsersGrid.dataProvider

                    [UsersGrid.selectedIndex]['COMPANY']}+"">Company link</a>" />

                    • 7. Re: Bind ahref link (like cfinput) in cfform
                      BKBK CommunityMVP

                      I have tested with:

                       

                      <cfdiv id = "companyDiv" bind="<a href=""mysite.com?company=+{company}+"">Company link</a>" />

                       

                      and it works! But then, just as you had guessed, the form field should already contain a value.

                       

                      Try this. Preload the cfinput by adding the attribute bindOnLoad="true".

                      • 8. Re: Bind ahref link (like cfinput) in cfform
                        goodychurro1 Community Member

                        Thanks for the input BKBK I tried with three different lines but I still get COMPANY not defined, I am using the code within the cfformgroup tag:

                         

                        1)

                        <cfdiv id = "companyDiv" bindOnLoad="true" bind="<a href=""mysite.com?company=+

                        {COMPANY}+"">Company link</a>" />

                        2)

                        <cfdiv id = "companyDiv" bindOnLoad="yes" bind="<a href=""mysite.com?company=+

                        {COMPANY}+"">Company link</a>" />

                        3)

                        <cfdiv id = "companyDiv" bindOnLoad="no" bind="<a href=""mysite.com?company=+

                        {COMPANY}+"">Company link</a>" />

                        • 9. Re: Bind ahref link (like cfinput) in cfform
                          BKBK CommunityMVP

                          The bindOnLoad suggestion is for <cfinput>, not for <cfdiv>. Please reread my post.

                          • 10. Re: Bind ahref link (like cfinput) in cfform
                            goodychurro1 Community Member

                            Cheers, OK I put the bindOnLoad on the cfinput COMPANY field:

                             

                            <cfinput type="text" bindOnLoad="true" name="COMPANY" label="Company" required="yes" width="200"

                            bind="{UsersGrid.dataProvider[UsersGrid.selectedIndex]['COMPANY']}" onChange="UsersGrid.dataProvider.editField

                            (UsersGrid.selectedIndex, 'COMPANY', COMPANY.text);">

                             

                            And this line also within the cfformgroup tag:

                            <cfdiv id = "companyDiv" bind="<a href=""mysite.com?company=+{COMPANY}+"">Company link</a>" />

                             

                            I get these three errors:

                             

                            bind failed element not found COMPANY

                            Element not found COMPANY

                            Element not found companyDiv

                             

                            Message was edited as I changed the case of database fields

                            • 11. Re: Bind ahref link (like cfinput) in cfform
                              BKBK CommunityMVP

                              I overlooked the fact you might be using a Flash form. The cfdiv tag is HTML. It won't work with Flash. In any case, not as we want here. However, we're on the right track. Convince yourself that this works:

                               

                              <cfform>

                                  <cfinput name="company" type="text" value="myCompany">

                              </cfform>

                              <cfdiv id = "companyDiv" bind="<a href=""mysite.com.cfm?company=+{company}+"">Company link</a>" />

                               

                              The challenge is to find an equivalent solution for a Flash form (update: which I am looking into). Alternatively, you could also look into converting your form into HTML.

                              • 12. Re: Bind ahref link (like cfinput) in cfform
                                goodychurro1 Community Member

                                Hi BKBK

                                I changed the cfform format and the cfgrid format to html but that makes none of the binds work!

                                 

                                I tried this code below the form and it works showing mycompany as the parameter, but the point obviously is that it is not dynamic.

                                The link doesn't have to be within the form. Maybe there is a way to set a variable with the value from the cfinput? Or have we hit a flash induced brick wall? Cheers

                                <cfform>

                                    <cfinput name="company" type="text" value="myCompany">

                                </cfform>

                                <cfdiv id = "companyDiv" bind="<a href=""mysite.com.cfm?company=+{company}+"">Company link</a>" />

                                • 13. Re: Bind ahref link (like cfinput) in cfform
                                  BKBK CommunityMVP

                                  goodychurro1 wrote:

                                   

                                  I changed the cfform format and the cfgrid format to html but that makes none of the binds work!

                                  It's usually not sufficient to change the format from flash to html. You may have to change the code in the bind expression from actionscript to an html-compatible form.

                                   

                                  I tried this code below the form and it works showing mycompany as the parameter, but the point obviously is that it is not dynamic.

                                  <cfform>

                                      <cfinput name="company" type="text" value="myCompany">

                                  </cfform>

                                  <cfdiv id = "companyDiv" bind="<a href=""mysite.com.cfm?company=+{company}+"">Company link</a>" />

                                  I didn't forget the requirement of passing the value dynamically via binding. This is just a proof of concept to show that there is a solution for HTML forms.

                                   

                                  The link doesn't have to be within the form. Maybe there is a way to set a variable with the value from the cfinput? Or have we hit a flash induced brick wall?

                                  Flash forms are trickier to manipulate in ColdFusion than HTML forms. However, there is always a way around most problems.

                                  • 14. Re: Bind ahref link (like cfinput) in cfform
                                    goodychurro1 Community Member

                                    Searching around the internet I found this code which when put in the cfform shows a list of all the company names with a link. There is no bind but it is interesting as a starting point mixing html in a flash form.  What do you think?

                                     

                                     

                                    <cfformgroup type="panel" label="Current forums" visible="Yes" enabled="Yes">

                                    <cfformitem type="html" visible="Yes" enabled="Yes">

                                    <cfloop query="qNames">

                                    <cfoutput><a

                                    href="threads.cfm?fid=#Company#">#Company#</a><br

                                    /></cfoutput>

                                    </cfloop>

                                    </cfformitem>

                                    </cfformgroup>

                                    • 15. Re: Bind ahref link (like cfinput) in cfform
                                      BKBK CommunityMVP

                                      goodychurro1 wrote:

                                       

                                      <cfformitem>

                                       

                                      Spot on! I have also been looking into <cfformitem type="html"> and <cfformitem type="script">

                                       

                                      I came up with:

                                       

                                      <cfformitem type="html" bind="<a href=""mysite.com?company={company.text}"">Company link</a>">

                                         </cfformitem>

                                       


                                      • 16. Re: Bind ahref link (like cfinput) in cfform
                                        goodychurro1 Community Member

                                        Thank you BKBK that works great! I learnt a lot about flash forms, I think I will have to eventually change it to html and the cfgrid as well (it appears that it can be done for both) but that is for another opportunity!