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

Custom user field, if checkbox user ...

Discussion in 'XenForo Development Discussions' started by Allan, Nov 26, 2014.

  1. Allan

    Allan Well-Known Member

    I have create an custom user field:

    Screenshot_18.png Screenshot_19.png

    Screenshot_20.png


    My html code:

    Code:
    <xen:if is="{$user.customFields.bloc_note} == 'on'">
    hide or show this content if custom user field checked
    </xen:if>
    I would like if the user checks the box, the content is displayed.

    But actually, don't work :(
     
  2. Snog

    Snog Well-Known Member

    This should work..

    Code:
    <xen:if is="{$user.customFields.bloc_note.on}">
    hide or show this content if custom user field checked
    </xen:if>
    
     
    Allan and Steve F like this.
  3. Allan

    Allan Well-Known Member

    After test, Always not.
     
  4. Insy

    Insy Well-Known Member

    The current user is $visitor, not $user !
    Code:
    <xen:if is="{$visitor.customFields.bloc_note.on}">
    hide or show this content if custom user field checked
    </xen:if>
     
    Allan and Snog like this.
  5. Snog

    Snog Well-Known Member

    Works every time in some quick tests here.

    There's either something else you're not telling us or $user isn't available where you're using it.

    EDIT: Or like @Insy said, you want $visitor, not $user.
     
    Insy likes this.
  6. Allan

    Allan Well-Known Member

    Work now, thanks guys ;)
     
  7. Allan

    Allan Well-Known Member

    Other question, how to ensure that the option is checked by default?
     
  8. Snog

    Snog Well-Known Member

    You can't directly set a default value for custom user fields.
     
  9. Allan

    Allan Well-Known Member

    Thank you for information.

    But how to display the content if the people don't see by default?
     
  10. Steve F

    Steve F Well-Known Member

    Code:
    <xen:if is="{$visitor.customFields.bloc_note.on}">
    hide or show this content if custom user field checked
    <xen:else />
    Show stuff here for people with option not checked
    </xen:if>
     
    Snog likes this.
  11. Allan

    Allan Well-Known Member

    Tried and don't work because if the user don't want to see the block, it will see still ..
     
  12. Steve F

    Steve F Well-Known Member

    So, what exactly are you trying to do? If a field is not set by default then the "<xen:else />" will run. It should work, but without seeing the actual code we have no idea.

    EDIT: You can try this as well.

    Code:
    <xen:if is="{$visitor.customFields.bloc_note.on} == 'on'">
    hide or show this content if custom user field checked
    <xen:else />
    Show stuff here for people with option not checked
    </xen:if>
     
    Allan likes this.
  13. Allan

    Allan Well-Known Member

    It work ! Thank you Steve F ;)

    Just for understand

    In <xen:if is="{$visitor.customFields.bloc_note.on} == 'on'">

    -> bloc_note -> custom ID field
    -> on -> Value to ID field

    And 'on' -> Activate ? it's correct ?

    And if i put off ? -> no activate ?
     
  14. Insy

    Insy Well-Known Member

    When the checkbox isn't checked, $visitor.customFields.bloc_note is NULL.
    It does not take the value 'off'.
     

Share This Page