Attribute in Profile

Permalink
Hi All,

I have created a user attribute for a user to enter his website upon registration. How would I make the website the user has entered in the field an active link people can click on in his profile? As it is, it only displays as text in the member profile page. I'd even be happy with the URL displaying in the sidebar as long as it was a live link. Can anyone point me to a "How to" that will help?

Thanks so much!
Hope

HopeL
 
HopeL replied on at Permalink Reply
HopeL
I found a way but doubt this the proper way. Surely there is a better way to accomplish this?
<a href='<?php echo "http://".$profile->getAttribute('website', 'displaySanitized', 'display'); ?>'><?php echo $profile->getAttribute('website', 'displaySanitized', 'display');?> </a>
mhawke replied on at Permalink Reply
mhawke
To tidy it up a bit, I might be inclined to set a variable:

<?php
$website = "http://" . $profile->getAttribute('website', 'displaySanitized', 'display');
?>


and then use the variable in the HTML

<a href="<?php echo $website ;?>"><?php echo $website;?></a>
HopeL replied on at Permalink Reply
HopeL
Thanks, mhawke! That works much better!
mhawke replied on at Permalink Best Answer Reply
mhawke
You should also make sure that the member hasn't already added the 'http' part when they entered their website information. Something like:

<?php
$parsed = parse_url($profile->getAttribute('website', 'displaySanitized', 'display'));
$website = 'http://' . $parsed['host'] . $parsed['path'];
?>
HopeL replied on at Permalink Reply
HopeL
Thanks. Before I get to the parse code, I have a question. In case the user does not have a website/enters nothing in the field, I would like to display nothing or a blank space. What it currently prints is http:// on the profile is user has no website. I tried messing around with an if else statement but have mangled it. The code below does not work (of course!). Any hints on how to get it working?
<?php
$website = "http://" . $profile->getAttribute('website', 'displaySanitized', 'display');
 if ( is_null($website) ) echo ' ';
else ('<a href="$website>" target="_blank">$website</a>');
?>


Also tried this but it only prints "No website" regardless of whether the user has one or not.
<?php
$website = "http://" . $profile->getAttribute('website', 'displaySanitized', 'display');
if ( is_null($website) || !is_object($website) || !intval($website->getAttribute())) { echo 'No website';
        } else {
        echo $website;
        }?>
mhawke replied on at Permalink Reply
mhawke
How about something like this:
$website = '';
$member_url = $profile->getAttribute('website', 'displaySanitized', 'display')
if ($member_url){
   $parsed = parse_url($member_url);
   $website = 'http://' . $parsed['host'] . $parsed['path'];
}
echo $website;
HopeL replied on at Permalink Reply
HopeL
Thanks. I tried it and am getting the following:
Parse error: syntax error, unexpected 'if' (T_IF) in domain.com/c5/single_pages/profile/view.php on line 21

It could be something I've messed up so I'll clean up some of the lines I've been adding.
HopeL replied on at Permalink Reply
HopeL
Okay... I added a ; on the end of one line and now it works but the URL is not an active url so to speak. It's just typing the text but maybe I can figure it out. :-)
HopeL replied on at Permalink Reply
HopeL
Okay.. Instead of echo $website; I used the following and it seems to work!

<a href="<?php echo $website ;?>"><?php echo $website;?></a>


Thank you!!
mhawke replied on at Permalink Reply
mhawke
Glad it's working.