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

XF 1.1 Change profile field by clicking a link

Discussion in 'XenForo Questions and Support' started by DBA, May 8, 2012.

  1. DBA

    DBA Well-Known Member

    Basically what I'm trying to do is have a link that will check a specific custom profile (preference) field (it's a single check box). And another to uncheck it. All without any further action by the user.

    Is that even possible?
  2. Chris D

    Chris D XenForo Developer Staff Member

    Where would this link be?
  3. DBA

    DBA Well-Known Member

    Part of the visitorTab.

    I'm trying to create an enable/disable chat link.


    I currently have it set to just link to the preferences page, where they have to check the box and click save. I'd rather have it do it automatically.
  4. Chris D

    Chris D XenForo Developer Staff Member

    I wouldn't personally know how to do this, though I will look.

    But I imagine that it might be possible to use the data writer feature so that once that link is pressed, it affects the change in the database table for the user.
  5. ragtek

    ragtek Guest

    something like

    $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
    $writer->setCustomFields(array('field_id' => 1));

    should work
    DBA likes this.
  6. DBA

    DBA Well-Known Member

    Thanks ragtek, but that's a little over my head. How would I get that in a clickable/link format?

    This is what I currently have.
        <xen:if is="{$visitor.customFields.dba_chat}">
            <li class="navTab PopupClosed"><a href="{xen:link account/preferences}" class="navLink visitorTabItem">Disable Chat</a></li>
        <xen:else />
            <li class="navTab PopupClosed"><a href="{xen:link account/preferences}" class="navLink visitorTabItem">Enable Chat</a></li>
  7. ragtek

    ragtek Guest

    it's not possible;)

    you'll need a custom addon, OR include a form link used for the toggle visibility, never done this, so not sure, but i think you'll only need to add the fieldid and sec token
    DBA likes this.
  8. DBA

    DBA Well-Known Member


    Well never mind then, thanks for your help ragtek. (y)
  9. ragtek

    ragtek Guest

    just to be sure

    you want this: foobar.PNG and on click on the navbar you'll get the popup and by confirming, the users profile field will be changed
    Yorick and DBA like this.
  10. DBA

    DBA Well-Known Member

    That would work. (y)
  11. DBA

    DBA Well-Known Member

    Ragtek, thanks for the code to get me started. (y)

    After some tweaking, I was enable to get it to be more "dynamic" (phrases change depending on which state you're in).





    Thanks again ragtek, I can already think of a couple other uses for this.
    Yorick likes this.
  12. Chris D

    Chris D XenForo Developer Staff Member

    I have a use for this as well but not to enable/disable chat, something else - is this being released as a full add on? Or could I have the files to customise them to our needs?
  13. DBA

    DBA Well-Known Member

    You'll have to ask him.
  14. ragtek

    ragtek Guest

    DBA can tweek/release it if he wants:)
  15. ragtek

    ragtek Guest

    and i'm glad you're able to use it and that you tweaked it:)
    Yorick and DBA like this.
  16. Chris D

    Chris D XenForo Developer Staff Member

    Thanks ragtek.

    DBA it's up to you. If you don't want to that's fine. It was made for you and modified by you so entirely your choice :)
  17. DBA

    DBA Well-Known Member

    I've attached the zip file that ragtek sent me.

    Couple things:
    • All phrases are hard coded.
    • Edit the custom profile field ID in the TF/config file.
    • Field type should be a check box and the value "on"
    I'm using this conditional to show whatever's inside it (if the custom profile is unchecked).

    Attached Files:

    Yorick likes this.
  18. Chris D

    Chris D XenForo Developer Staff Member

    Excellent, thank you. :)

    And of course, thank you Ragtek, good work.

Share This Page