Skip to Content Skip to Menu

🌟Discover the Joomla AI Plugin that wrote its own story! - CB Editor Assistant 1.1now for Joomla 3, 4 & 5!
✍️ 5-Day Free Trial, then 🎯 save up to 30% with our 🛍️ Intro Offer (First 50 users, ends Dec. 25th)
🌲 Merry Christmas! Great savings on Professional and Developer Memberships! Get 25% off now with code XMAS-2024!

PHP code for linkable records

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
7 months 1 week ago - 7 months 1 week ago #338130 by galanopd
PHP code for linkable records was created by galanopd
I have a query field nested within a field group, which retrieves data from a database table and presents it in a table-like format using the parameters set in Parameters->Display->Multiple rows->Multiple columns. One of the columns, column_website, contains external URLs. I've successfully made it linkable within the <td> tag using <a> elements, but there's an issue: when clicked, the website address gets appended to the end of my website address. Much probably the [column_website] value is using a relative URL rather than an absolute one, and my records in the database table do not include the "http://" or "https://" protocol.

To be sure that the website links work correctly in the front-end, I need to format them as absolute URLs. As I've mentioned above, my records in the db table do not include the "http://" or "https://" protocol but in the future they may vary in their URL format, like
Code:
http://www.test.com, http://test.com, https://www.test.com, https://test.com, www.test.com, test.com

To address this, I need to use some PHP code like:
Code:
$website_url = "[column_website]"; if (strpos($website_url, 'http://') === 0 || strpos($website_url, 'https://') === 0) {     echo $website_url; } else {     if (strpos($website_url, 'www.') === 0) {         echo 'http://' . $website_url;     } else {         echo 'http://www.' . $website_url;     } }

in order to handle these cases and make sure that the URLs are properly formatted as absolute URLs.

Can you suggest how to implement this to make sure that the website links are consistently formatted as absolute URLs and function correctly in the front-end?

Any guidance would help...
Last edit: 7 months 1 week ago by galanopd.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48616
  • Thanks: 8302
  • Karma: 1446
7 months 1 week ago #338135 by krileon
Replied by krileon on topic PHP code for linkable records
Use SQL functions to format them as needed so the resulting substitution will be as desired. Your only other option is custom template for your query field and then you can use PHP against the resulting SQL to format it however you want.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.
The following user(s) said Thank You: galanopd

Please Log in or Create an account to join the conversation.

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
7 months 1 week ago - 7 months 1 week ago #338137 by galanopd
Replied by galanopd on topic PHP code for linkable records

Use SQL functions to format them as needed so the resulting substitution will be as desired.

That worked,

Thank you
Last edit: 7 months 1 week ago by galanopd.
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum