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

XF 1.2 Can you set a profile field selection in a template?

Discussion in 'Styling and Customization Questions' started by Phases, Nov 30, 2013.

  1. Phases

    Phases Active Member

    I'm wondering, can I do this:

    Link that already does stuff <-- click, it does stuff. I'd like it to also set profile_field = "Yes" on click.

    Another link that already does stuff <-- click, it does its stuff, but I'd like it to also set profile_field = "No" on click.

    ?
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    When you say "it already does stuff" what do you mean?
     
  3. Phases

    Phases Active Member

    Currently it slides open a box, the slides it back closed. Just like the "Thread Display Options" accordion dropdown.

    I'm hoping with some trickery I can pull off a "set profile field x to yes" at the same time.
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    Is this custom code?
     
  5. Phases

    Phases Active Member

    Well yes.
     
  6. AndyB

    AndyB Well-Known Member

    You could use the xen:callback tag and have a PHP script update your database table directly.
     
    Phases likes this.
  7. Jeremy

    Jeremy XenForo Moderator Staff Member

    A xen:callback is inappropriate here. It won't be able to accomplish what he wants.

    If the JavaScript is custom already, add in a simple jQuery selector to find the input and inverse it's value.
     
    Phases likes this.
  8. Phases

    Phases Active Member

    I'm not sure I'm following, I was hoping for more of a explanation than that - I barely follwed - but I'll google it and see if I can figure it out. jQuery selector.. got it.
     
  9. AndyB

    AndyB Well-Known Member

    When you say "profile_field", do you mean a Custom User Field?
     
  10. Phases

    Phases Active Member

    Yeah, sorry!
     
  11. AndyB

    AndyB Well-Known Member

    You can add PHP code to the "Link that already does stuff" to update the Custom User Field. You need to select the database and have a query update the correct table.
     
  12. Phases

    Phases Active Member

    Awesome, I believe I can handle that! Thanks!
     
    AndyB likes this.
  13. Jeremy

    Jeremy XenForo Moderator Staff Member

    Andy, you cannot use PHP to change the value on a page after it's loaded. Regardless, unless the link that "expands a box and already does stuff" causes a new page load, you cannot use PHP and will have to use JavaScript.
     
  14. Phases

    Phases Active Member

    Dern. I would be able to figure out PHP lol.

    Imaging the "Thread Display Options" dropdown when viewing threads in a forum. You know how you can click it to scroll it down, then click again to scroll it up. I use another block elsewhere using code based from that, it does the same thing. I want to update a custom profile field from fiend 1 to field 2 when expanding, then back from field 2 to field 1 when closing. Pretty much explains it. I could sort php/sql, but JS would be a challenge for me.
     

Share This Page