5 Replies Latest reply on Dec 14, 2009 6:16 AM by hermes980

    cfoutput text with clickable URL


      Hi all,


      I have a cfoutput that is displaying text from a database (Users enter text in a form that inputs it into a DB). As part of this entry, users can enter text including any url. However, when I output the results of what has been entered, the URLs are not clickable. The links can be anywhere in the forum post. (ex. "Check this out http://www.google.com" or "http://www.google.com Check this out")


      How do I output text that may or may not include a URL and have that URL be clickable?


      Thanks in advance!

        • 1. Re: cfoutput text with clickable URL
          ilssac Level 5

          If you want a browser to display a URL as a clickable link, that URL must be inside a properly formated <a>nchor tag.  If your users are just entering URLS in the text, and not anchor tags you have two choices.


          Train your users to enter proper anchor tags in the data.


          Create a processor that will find the url's in the text and dynamically build a URL around it.


          The latter is probably easier, but it is not trival.  Your best hope would be to find some code where somebody has already done this for you.  CFLIB [http://www.cflib.org/] is a great place to try first.

          • 2. Re: cfoutput text with clickable URL
            hermes980 Level 1

            I have found several articles related to javascript and searching for URLs to convert to links, but am unsure on how to implement these with cfoutput.


            Another thought would be to convert the text input to html. Is there a way to have the form create html from text. Or does the rich text editor insert what is entered as html?


            My thought here is to get the html in, and it will be easier to output.

            • 3. Re: cfoutput text with clickable URL
              hermes980 Level 1

              Okay, I have made some progress but not quite there. I am using REReplace with the my outputted variable (I found this regex online). It finds http:// and https:// and they link perfectly... but does not make www. a working link. The www. will be highlighted as a link, but it does not put the http:// in front of it. Here is my code:


              <p>#REReplace(my.variable,"((((https?:)\/\/)|(www\.))[-[:alnum:]\?%,\.\/&##!@:=\+~_]+[A-Za -z0-9\/])", "<a href=""\1"" target=""_blank"">\1</a>", "ALL")#</p>


              Any help is appreciated (and any easier methods is more appreciated!)

              • 4. Re: cfoutput text with clickable URL
                satheesh_p Level 1

                I am not sure the below helps you. Can you please try with the following options?

                1) Use HTMLEditFormat or HTMLCodeFormat.

                2) Try to use replace command while selecting the column in the database query itself and checking with <cfoutput>.




                • 5. Re: cfoutput text with clickable URL
                  hermes980 Level 1

                  No luck on #1. I am using a cfoutput query, how would I use your #2 suggestion?