• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

cfoutput text with clickable URL

Guest
Dec 09, 2009 Dec 09, 2009

Copy link to clipboard

Copied

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!

TOPICS
Advanced techniques

Views

865

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 09, 2009 Dec 09, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 13, 2009 Dec 13, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 13, 2009 Dec 13, 2009

Copy link to clipboard

Copied

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!)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 14, 2009 Dec 14, 2009

Copy link to clipboard

Copied

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>.

Thanks,

Satheesh.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 14, 2009 Dec 14, 2009

Copy link to clipboard

Copied

LATEST

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

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation