XF 1.1 Change profile field by clicking a link

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?
 
Where would this link be?
Part of the visitorTab.

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

Untitled.webp

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.
 
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.
 
something like


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

should work
 
  • Like
Reactions: DBA
something like


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

should work
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.
Code:
    <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>
    </xen:if>
 
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
 
  • Like
Reactions: DBA
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).

chat.webp

chat2.webp

chat3.webp

chat4.webp


Thanks again ragtek, I can already think of a couple other uses for this.
 
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?
 
DBA can tweek/release it if he wants:)
Thanks.
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 :)
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).
<xen:if is="!{$visitor.customFields.insert_fieldID_here}">
text to be shown
</xen:if>
 

Attachments

Thanks.

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

Excellent, thank you. :)

And of course, thank you Ragtek, good work.
 
Top Bottom