• 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

DBA

Well-known member
#1
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?
 

DBA

Well-known member
#3
Where would this link be?
Part of the visitorTab.

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

Untitled.png

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.
 

Chris D

XenForo developer
Staff member
#4
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.
 
R

ragtek

Guest
#5
something like


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

should work
 

DBA

Well-known member
#6
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>
 
R

ragtek

Guest
#7
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
 
R

ragtek

Guest
#9
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
 

DBA

Well-known member
#11
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.png

chat2.png

chat3.png

chat4.png


Thanks again ragtek, I can already think of a couple other uses for this.
 

Chris D

XenForo developer
Staff member
#12
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

Well-known member
#17
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

Chris D

XenForo developer
Staff member
#18
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.