vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Displaying HTML based on a profile switch (https://vborg.vbsupport.ru/showthread.php?t=289507)

Daryn 10-23-2012 03:28 PM

Displaying HTML based on a profile switch
 
I'm looking to setup a simple On/Off Radio button in our profile fields. Based on whether that is set to on or off, I'd like to be able to display a certain bit of HTML on the forum home. Does anyone know how this can be done?

kh99 10-24-2012 05:43 PM

First go to the User Profile Field menu in the adminCP and choose "Add New User Profile Field". When you've added your new radio button field, in the Profile Field Manager you can see what ID the new field was assigned, and then in a template you can check for the value. For instance if your new field is ID 8, then you'd check the value of $bbuserinfo[field8], like:

Code:

<if condition="$bbuserinfo[field8] == 'Yes'">
Yes
<else />
No
</if>


But there's one other thing to note: when you add a field, all users will have a blank value for that field until they edit their profile and save it. So if you add a radio button with options Yes and No, you have to also handle the possibility of the value being blank. (You can do that by checking for the non-default value in your if condition. For instance, in the above example a blank field would act the same as 'No' because we checked for 'Yes').

Daryn 10-24-2012 07:04 PM

I suppose that I could set the default value of that field for all users via SQL. Not sure what the query would be for that, but it should be possible, no?

kh99 10-24-2012 07:40 PM

You could do that. It should just be something like:
Code:

UPDATE userfield SET fieldX = 'Yes' WHERE fieldX = ''

Where of course you'd use the field id place of X and put whatever default you want in place of 'Yes'.

Daryn 10-24-2012 09:25 PM

That works brilliantly. Thanks a lot! I think I'll be making good use of that now that I know how it's done.


All times are GMT. The time now is 05:32 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03449 seconds
  • Memory Usage 1,715KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete