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

Discussion in 'XenForo Questions and Support' started by Anton_Bodryachkom, Apr 29, 2015.

  1. Anton_Bodryachkom

    Anton_Bodryachkom Active Member

  2. Chris D

    Chris D XenForo Developer Staff Member

    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>
     
    sbj likes this.
  3. Anton_Bodryachkom

    Anton_Bodryachkom Active Member

    thank you very much ,it gives me this
    [​IMG]
     
  4. Chris D

    Chris D XenForo Developer Staff Member

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

    sbj Well-Known Member

    Very interesting. Thanks for this.
    Is it also possible to show only the name of the url instead of the whole url?
    So instead of
    https://www.xenforo.com
    only
    xenforo
    ?
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    No, you only have access to a certain number of variables (which are described below the field).
     
  7. sbj

    sbj Well-Known Member

    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 ?
     
  8. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
    creativeforge likes this.
  9. sbj

    sbj Well-Known Member

    No need to apologise. You are trying to help, thanks.
    Just... it still gives the same error. Strange.
     
  10. Chris D

    Chris D XenForo Developer Staff Member

    The version I posted in my last post definitely works for me.
     
  11. sbj

    sbj Well-Known Member

    Hmm, strange. It should also work for me but it keeps putting the websites name in front of the url typed in.
    Can't figure it out why this happens.
     
  12. sbj

    sbj Well-Known Member

    For people who have the same issue:

    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>
     
  13. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
    sbj likes this.
  14. Anton_Bodryachkom

    Anton_Bodryachkom Active Member

    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

    [​IMG]
     
  15. sbj

    sbj Well-Known Member

    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.
     
  16. Chris D

    Chris D XenForo Developer Staff Member

    If a field can contain non URLs then you can't format it as a URL.
     
  17. Anton_Bodryachkom

    Anton_Bodryachkom Active Member

    i think its opposite with me . even if its not url , it makes it as link . hmm
     
  18. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
    sbj likes this.
  19. Chris D

    Chris D XenForo Developer Staff Member

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

    Anton_Bodryachkom Active Member

    ok . sorry Chris , i misunderstood code . my bad :/
     

Share This Page