PDA

View Full Version : On/off or yes/no conditional help, please.


Guest210212002
10-08-2008, 03:35 PM
I'm trying to set a simple conditional to allow my members to enable/disable a sidebar based on usergroup permissions.

I have a CPF (field18), Single-Selection Radio Buttons, with the options being "Yes" and "No".

In the user's profile options page, is an option: "Display the sidebar? (o) Yes ( ) No".

If the YES button is checked, I want a conditional to display the respective code. From what I can tell by hunting around vb.com, this should work:

<if condition="$post[field18] == 'Yes'">

But it doesn't. :\

What would the proper yes/no (or on/off) conditional syntax be?

Thanks!

Lynne
10-08-2008, 03:44 PM
What template are you using that condition in? I think that particular one - $post[field18] - is only available on the showthread page (and, I think it has to do with the poster, not the viewer, and you want the viewer, yes?). Have you tried $vbulletin->userinfo[field18] ?

Guest210212002
10-08-2008, 03:46 PM
That first part would certainly explain a lot, this is driving me nuts.

So what you're saying is:

<if condition="$userinfo[field18] == 'Yes'">

Correct?

/me goes off to try that

noppid
10-08-2008, 03:47 PM
The values are returned as 1 and 2, it's a number that is returned, not the text.

</fieldset><fieldset class="fieldset">
<legend>test</legend>
<table cellpadding="0" cellspacing="3" border="0" width="100%">
<tr>
<td>test</td>
</tr>
<tr>

<td>
<table cellpadding="2" cellspacing="0" border="0">
<tr><td valign="top"><label for="rb_cpf_field10_1"><input type="radio" name="userfield[field10]" value="1" id="rb_cpf_field10_1" checked="checked" />yes</label></td></tr><tr><td valign="top"><label for="rb_cpf_field10_2"><input type="radio" name="userfield[field10]" value="2" id="rb_cpf_field10_2" />no</label></td></tr>
</table>
<input type="hidden" name="userfield[field10_set]" value="1" />
</td>
</tr>


</table>
</fieldset>



look at the source output on edit profile. ;)

Guest210212002
10-08-2008, 03:48 PM
This is what I tried, which didn't do it. I'm doing it on Forumhome:


<if condition="THIS_SCRIPT == 'index'">
<if condition="$userinfo[field18] == 'Yes'">

Lynne
10-08-2008, 03:48 PM
That first part would certainly explain a lot, this is driving me nuts.

So what you're saying is:

<if condition="$userinfo[field18] == 'Yes'>

Correct?

* Chris-777 goes off to try that
In my navbar template, I actually use:
<if condition="$vbulletin->userinfo[field13] <> 'Yes'">
stuff for when it isn't set to Yes
</if>

Guest210212002
10-08-2008, 03:49 PM
The values are returned as 1 and 2, it's a number that is returned, not the text.

Also doesn't work:


<if condition="THIS_SCRIPT == 'index'">
<if condition="$userinfo[field18] == '1'">

The first part is correct (eg: that alone displays my code), so I think Lynne's on target with the thinking that I need a global conditional, or at least one that works on the index.

--------------- Added 1223488271 at 1223488271 ---------------

In my navbar template, I actually use:
<if condition="$vbulletin->userinfo[field13] <> 'Yes'">
stuff for when it isn't set to Yes
</if>

If there was a way I could fedex you a cake right now, I would. You are absolutely AWESOME Lynne, that works - thank you VERY much as usual! :D

--------------- Added 1223488339 at 1223488339 ---------------

While I'm at it (though I should probably start a new thread) - how would I go about setting usergroup permissions on my shiny new on/off CPF? :D The idea here is that contributers can turn something on/off, whilst regular registered users cannot.

noppid
10-08-2008, 03:57 PM
You need a hook after the userinfo is sorted out, yes.

Ok, it's passed from the form as 1 and 2 and stored for comparison in the field as the text, so go with that when comparing.

Secondly. until you go to the profile page and click yes, the field will be blank. eg, the comparison will always fail.

Lynne
10-08-2008, 04:02 PM
If there was a way I could fedex you a cake right now, I would. You are absolutely AWESOME Lynne, that works - thank you VERY much as usual! :D
Cheesecakes are a particular favorite of mine - no fruit on top, please. Just saying.... :D
While I'm at it (though I should probably start a new thread) - how would I go about setting usergroup permissions on my shiny new on/off CPF? :D The idea here is that contributers can turn something on/off, whilst regular registered users cannot.
As far as I know, you cannot put permissions on the option in the UserCP. But, what you may be able to do is in the 'text' for the setting, say it's a premium feature. That way, they can set it to whatever they want, but it shouldn't have an effect if you set a conditional with it like:

<if condition="$vbulletin->userinfo[field18] == 'Yes' AND is_member_of($bbuserinfo,5,6)">
stuff for users who said Yes in field 18 and are members of usergroup 5 or 6
</if>

(I use that condition in the same template.... makes me wonder if you can use $bbuerinfo instead of $vbulletin->userinfo... I'll have to try that later.)

noppid
10-08-2008, 04:03 PM
(I use that condition in the same template.... makes me wonder if you can use $bbuerinfo instead of $vbulletin->userinfo... I'll have to try that later.)

That'll work. Good going. :)

Guest210212002
10-08-2008, 04:09 PM
Hmm, that sort of works, I see what you mean. If I just add that in there like this:

<if condition="$vbulletin->userinfo[field18] <> 'No' AND is_member_of($bbuserinfo,5,6)">
(sidebar code)

then If it's set to Yes, and I'm in the right group, it shows the code.

But if someone NOT in that usergroup has it set, then the conditional isn't matched and the code doesn't show.

I might need to use a bunch of else's here, eh?

--------------- Added 1223489616 at 1223489616 ---------------

* Guest210212002 hasn't had enough coffee

What I need here is a conditional to ignore the yes/no conditional for everyone BUT contributors. That way the code is shown to everyone who does NOT have permission to use the yes/no thing.

Does that make sense?

Lynne
10-08-2008, 04:15 PM
I don't understand what you are saying.... If someone not in the usergroup (right now with your statement, only usergroup 5 and 6 which are admins/super mods) sets field18, it should not do a thing for them. Isn't that what you want?

Guest210212002
10-08-2008, 04:27 PM
My head hurts. :D

Here's my layout. Without conditionals, I have sidebar code for everyone. Then I want to only show it on the index, so I added this:

<if condition="THIS_SCRIPT == 'index'">

Then I want it to show or not show, based on the CPF, so I added this:

<if condition="$vbulletin->userinfo[field18] <> 'No'">

That works right now, for everyone - they can all show or hide the sidebar (huzzah!).

So my code looks like:

<if condition="THIS_SCRIPT == 'index'">
<if condition="$vbulletin->userinfo[field18] <> 'No'">

Hooray, this is my sidebar!



What I need to do now is ignore the on/off conditional for everyone BUT me (for starters). That way, regardless of what a not-me person sets the CPF to, it displays anyway. What I tried was this:


<if condition="THIS_SCRIPT == 'index'">
<if condition="in_array($bbuserinfo['usergroupid'], array(5, 6))">
<if condition="$vbulletin->userinfo[field18] <> 'No'">
</if>


Thinking that the new and improved on/off conditional would only actually register for for my usergroup. So if the usergroup didn't match 5 or 6, the code would display anyway. If the usergroup DID match 5 or 6, and the conditional was set to Yes, it would display the code.

Unfortunately that didn't work. :( With that setup, the sidebar always shows. Basically what I need is for it to show to everyone, unless they are in group 5/6, and if they are in group 5/6, only if the on/off conditional is set to Yes.

Lynne
10-08-2008, 04:35 PM
Let me get this straight..... You want "Hooray, this is my sidebar" (using the example) to show for everyone *unless* they are in group 5/6, and if they are in group 5/6, only if the on/off conditional is set to Yes.

<if condition="THIS_SCRIPT == 'index'">
<if condition="(in_array($bbuserinfo['usergroupid'], array(5, 6)) AND $vbulletin->userinfo[field18] <> 'No') OR !in_array($bbuserinfo['usergroupid'], array(5, 6))">
Hooray, this is my sidebar
</if>
</if>Now my head hurts, too!

Guest210212002
10-08-2008, 04:38 PM
I am so sorry. :D

Yes, you have it right. That conditional gives me a malformed error though, but I think that's the right idea.

--------------- Added 1223492073 at 1223492073 ---------------

I think I finally got it! Your conditional was just missin' one closing parenthesis (or my browser is bad at copy/paste)


<if condition="(in_array($bbuserinfo['usergroupid'], array(5, 6)) AND $vbulletin->userinfo[field18] <> 'No') OR !in_array($bbuserinfo['usergroupid'], array(5, 6))">


Lynne you are AWESOME, thanks again so much!

Lynne
10-08-2008, 06:25 PM
You must have grabbed my condition as soon as I posted it cuz I modified it less than a minute later to add the closing parenthesis!