View Full Version : Adding comma when needed in custom profile (postbit legacy)
tiztoz
11-05-2015, 09:51 PM
I have created two custom profile fields.
the first one includes 20 teams and the user can choose only one
the second has also 20 teams and the user can choose only one.
This is my code :
<if condition="$post['field11']"><div class="CommUserInfo">team : $post[field11] , $post[field12]</div></if>
The problem with my code is that it always puts the comma , I want it to add the comma only if the user chooses two teams ( one from each group) , while if the user chooses only one team , it does not add the comma.
Lynne
11-06-2015, 05:34 PM
Do they have to choose something in each field - 11&12? Or only in one field - only in 11? Give us some of those details and then we can write up some conditions.
PinkMilk
11-06-2015, 05:47 PM
<if condition="$post['field11']"><div class="CommUserInfo">team : $post[field11]<if condition="$post['field12']"> , $post[field12]</if></div></if>
Would this not work?
tiztoz
11-06-2015, 06:13 PM
<if condition="$post['field11']"><div class="CommUserInfo">team : $post[field11]<if condition="$post['field12']"> , $post[field12]</if></div></if>
Would this not work?
Works like charm :up:
Dragonsys
11-07-2015, 09:22 AM
<if condition="$post['field11']"><div class="CommUserInfo">team : $post[field11]<if condition="$post['field12']"> , $post[field12]</if></div></if>
Would this not work?
You will still get the comma if field 11 is left blank. try this:
<if condition="$post['field11']"><div class="CommUserInfo">team : $post[field11] <if condition="$post['field11'] AND $post['field12']">, </if><if condition="$post['field12']">$post[field12]</if></div></if>
This will leave out the comma if only 1 field is selected, but show it, if both have a value.
Lynne
11-07-2015, 05:41 PM
Actually, if field11 is left blank, nothing will show because of the initial condition around the whole line.
Dragonsys
11-07-2015, 10:01 PM
Actually, if field11 is left blank, nothing will show because of the initial condition around the whole line.
Yep, I missed that. Here is the corrected code
<div class="CommUserInfo">team : <if condition="$post['field11']">$post[field11]</if><if condition="$post['field11'] AND $post['field12']">, </if><if condition="$post['field12']">$post[field12]</if></div>
If you want to hide the entire line if neither field has a value: (not tested, but it should work)
<if condition="$post['field11'] OR $post['field12']"><div class="CommUserInfo">team : <if condition="$post['field11']">$post[field11]</if><if condition="$post['field11'] AND $post['field12']">, </if><if condition="$post['field12']">$post[field12]</if></div></if>
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.