vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   If custom field is set to x then do y (https://vborg.vbsupport.ru/showthread.php?t=294524)

eviljoker7075 01-29-2013 01:36 PM

If custom field is set to x then do y
 
Hi, I have setup a radio button custom field. In my postbit template I'd like to add some code that shows a line of text next to each users post depending on what option they have selected in the custom field.

Basically the logic is:
If the user who made this post has option 1 set then show [this piece of code]. If they have option 2 selected then show [this other piece of code].

Can anyone help me write that?

kh99 01-29-2013 02:12 PM

It should be something like:
Code:

<vb:if condition="$post['fieldX'] == 1">
Something
<vb:else />
Something else
</vb:if>


and of course you'd use the actual field number in place of X.

eviljoker7075 01-29-2013 02:33 PM

Thanks for the quick response, I can't seem to get that code working though. Here's what I have:

A custom field, of 'single-selection radio button' type. It has three options 'one', 'two' and 'three.

The code I added to my postbit template:
PHP Code:

<vb:if condition="$post['field13'] == 1">
    
One selected
<vb:if condition="$post['field13'] == 2">
    
Two selected
<vb:else />
    
Something other than one or two selected
</vb:if> 

I have got option 1 ('one') selected but the test that's returned in the page is "Something other than one or two selected"

kh99 01-29-2013 02:53 PM

Oh, right. If the options are 'one', 'two' and 'three' then you have to check for those strings, like

Code:

<vb:if condition="$post['field13'] == 'one'">
    One selected
<vb:elseif condition="$post['field13'] == 'two'" />
    Two selected
<vb:else />
    Something other than one or two selected
</vb:if>


Edit: also there's an elseif you can use, I changed the above to show how you'd use it.

eviljoker7075 01-29-2013 03:04 PM

Ah, sorry I should have been clearer from the start. I also noticed I'd nested my if statements incorrectly. The final snippet I used looks like:

PHP Code:

<vb:if condition="$post['field13'] == 'One'">
    
One selected
</vb:if> 

Thanks very much :)


All times are GMT. The time now is 11:38 PM.

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.01473 seconds
  • Memory Usage 1,719KB
  • 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
  • (2)bbcode_php_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