• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.4 Custom user fields , URL clickable

Chris D

XenForo developer
Staff member
#2
Yes.

When editing the field, under "General Options" you can specify a template in the "Value Display HTML" field, e.g.

HTML:
<a href="{$valueUrl}">{$value}</a>
 

Chris D

XenForo developer
Staff member
#4
There must be something else on that page giving that error, or something else that isn't set right.

There's no validation, as such, on that field. It should accept anything, so it must be some other field that doesn't have a valid value.

It's worth noting that add-ons can sometimes cause this behavior so if you can't immediately see the problem, try disabling all add-ons and try again.
 

sbj

Well-known member
#7
Sorry to hijack your thread @Anton_Bodryachkom , I have another question.

So I did this:
Code:
<a href="{$valueUrl}" target="_blank">{$value}</a>
but it doesn't work.
The opened page always is like:
Code:
www.MyForumName.com/{$value}
So it puts all the time my forums' url-name in front of the valid url.

What is wrong here @Chris D ?
 

Chris D

XenForo developer
Staff member
#8
I apologise it should be:

HTML:
<a href="{$value}" target="_blank">{$value}</a>
{$valueUrl} would be used if it was, for example, some sort of parameter that should go inside a URL. Otherwise the {$value} should be used instead.
 

sbj

Well-known member
#9
I apologise it should be:

HTML:
<a href="{$value}" target="_blank">{$value}</a>
{$valueUrl} would be used if it was, for example, some sort of parameter that should go inside a URL. Otherwise the {$value} should be used instead.
No need to apologise. You are trying to help, thanks.
Just... it still gives the same error. Strange.
 

sbj

Well-known member
#12
For people who have the same issue:

The version I posted in my last post definitely works for me.
I identified the problem. If you just enter:
Code:
www.mywebsite.com
mywebsite.com
It won't work. At least it doesn't work for me.
It requires the user to put in the full url with http in front of it:
Code:
http://www.mywebsite.com
Then it works. What a bad behaviour... Which user would do that?...

Anyway, I bypassed this by doing:

Code:
<a href="http://{$valueUrl}" target="_blank">{$value}</a>
 

Chris D

XenForo developer
Staff member
#13
A URL is technically only valid if it includes the scheme such as http://

You should set the value match requirements to URL which would assert a valid URL is entered and remove the http:// bit from the display value.
 
#14
thnx again , but for me , when i use
<a href="{$value}" target="_blank">{$value}</a>

anything i enter , its makes it as link ...
if it possible to make it int hotlink when www detected

 

sbj

Well-known member
#15
A URL is technically only valid if it includes the scheme such as http://

You should set the value match requirements to URL which would assert a valid URL is entered and remove the http:// bit from the display value.
Well, I never ever use the http:// way when I type in a link. It took a bit to realize that this is the problem.

And with matching requirements to URL, the display of url in message user info is that big long http://www. displaying.
As you may know the message user info on left side has almost no space. It takes 3 lines to display a domain with 10 characters. And it looks ugly.
At least my way, you can save 7 characters (http://) + 3 characters (www, depends on your redirecting). So now my method displays mywebsite.com in 1 line, whereas the normal way displays it as http:///www.mywebsite.com in 3 lines.

But thanks, I learned a new thing today. I didn't know about the {$value} method for custom user fields.
 

Chris D

XenForo developer
Staff member
#18
Well, I never ever use the http:// way when I type in a link. It took a bit to realize that this is the problem.

And with matching requirements to URL, the display of url in message user info is that big long http://www. displaying.
As you may know the message user info on left side has almost no space. It takes 3 lines to display a domain with 10 characters. And it looks ugly.
At least my way, you can save 7 characters (http://) + 3 characters (www, depends on your redirecting). So now my method displays mywebsite.com in 1 line, whereas the normal way displays it as http:///www.mywebsite.com in 3 lines.

But thanks, I learned a new thing today. I didn't know about the {$value} method for custom user fields.
Problem is though you can't always assume a URL will be prefixed with http:// (it might be https://) and you can't always assume that www. will work. Adding either of these things technically make it a completely different URL. Also your method won't stop people from adding the http:// or www. again. So that will really break things.

You can't have it all ways. If you want it to be a URL it must be asserted as a valid URL or expect it to be broken.
 

Chris D

XenForo developer
Staff member
#19
i think its opposite with me . even if its not url , it makes it as link . hmm
Of course it will make it a link, that's what you have told it to do.

If you want people to enter stuff in there that might not be a URL then you have to remove the display HTML and just never have links.