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