View Full Version : Custom profile field conditionals for check boxes
WorldCraft
09-12-2012, 07:33 PM
Hello. I'm trying to get some conditionals working for a Multiple Selection Checkbox profile field I've set.
I tried the following conditional, but it doesn't work with checbox values:
<vb:if condition="$bbuserinfo[fieldX] == 'Show Me'">
<script> Do stuff here </script>
</vb:if>
However, it works fine with Radio button values. I am making sure that the fieldX and Field ID's match, and that the option names are matching exactly as well.
Any ideas why it doesn't work with checkboxes?:confused:
Scanu
09-12-2012, 07:51 PM
First option
<vb:if condition="$bbuserinfo[fieldX] & 1">
<script> Do stuff here </script>
</vb:if>
Second option
<vb:if condition="$bbuserinfo[fieldX] & 2">
<script> Do stuff here </script>
</vb:if>
Third option
<vb:if condition="$bbuserinfo[fieldX] & 4">
<script> Do stuff here </script>
</vb:if>
4th option
<vb:if condition="$bbuserinfo[fieldX] & 8">
<script> Do stuff here </script>
</vb:if>
etc...
WorldCraft
09-12-2012, 11:27 PM
Thanks, that works nice. The next thing I'm trying to do is that when User A views User B's profile, User A will see the effects as User B has set them. And vice versa.
The checkboxes they can pick create special effects to make their profile page look nicer.
Similar to how $post['fieldX'] will display information in the user's postbit, is there a condition statement or variable that will do this for user profiles?
Sorry if this request sounds confusing.
Scanu
09-12-2012, 11:33 PM
I'm not sure if i understand you, are you trying to do this (https://vborg.vbsupport.ru/showthread.php?t=287658)
WorldCraft
09-12-2012, 11:37 PM
Just re-worded the post. Sorry, I did word that pretty badly.
I'm trying to give my users bit more freedom with how their profiles look. So I've given them a few checkbox choices they can pick to give them some effects with Javascript.
Is there a statement, or variable, that will show the customizations the user chose when others see their profile, similar to the way that $post['fieldX'] will display customized information in the postbit? But in this case, on the member.php page.
Scanu
09-13-2012, 12:00 AM
Yes that's exactly what i figure out about an hour go :D Do you want this conditional to work in a plugin or in a template
WorldCraft
09-13-2012, 12:09 AM
Oh nice. :) Well I was planning to put all of the statements and scripts in the headinclude templates. Could it all be done there, or do you think a plugin would be best?
Edit I found that the method you displayed in the 2nd post is not working for me. It appears to work fine for the first 2 check boxes, but if I pick any further choices it will run the incorrect script, or multiple scripts, as if it's ignoring the condition. Even if I only choose 1 check box. It's weird because it only behaves in that way for box #3 and onwards. :(
Scanu
09-13-2012, 09:44 AM
Can you show me your code? And i think it's better to do this in a plugin since i understand you just want to add js files to the page, am i right?
WorldCraft
09-14-2012, 02:20 AM
Yes, but the obstacle I'm at is getting conditionals that check if a certain checkbox or checkboxes are selected.
For a quick concept test I put the following in my headinclude template:
<vb:if condition="$bbuserinfo[field16] & 1">
<script> alert("You chose checkbox 1!") </script>
</vb:if>
<vb:if condition="$bbuserinfo[field16] & 2">
<script> alert("You chose checkbox 2!") </script>
</vb:if>
<vb:if condition="$bbuserinfo[field16] & 3">
<script> alert("You chose checkbox 3!") </script>
</vb:if>
<vb:if condition="$bbuserinfo[field16] & 4">
<script> alert("You chose checkbox 4!") </script>
</vb:if>
<vb:if condition="$bbuserinfo[field16] & 5">
<script> alert("You chose checkbox 5!") </script>
</vb:if>
It doesn't seem to work properly. For example, if I choose checkbox 1, it will display alerts 1, 3, and 5. If I choose checkbox 2, it will display alerts 2, and 3. Checkbox 3 will display alerts 4 and 5. Checkboxes 4 and 5 will not run any script. I'm pretty new at coding so I'm not finding any obvious pattern and they seem to be executing at random.
Scanu
09-14-2012, 10:21 AM
You must redouble the number each time...
e.g. (1,2,4,8,16,32,64 etc..)
WorldCraft
09-14-2012, 05:51 PM
Oh wow....didn't notice you were doubling those in your first post. Sorry. :o
Anyway, if a plugin is best then let's go with that. And yes, just one javascript file for each checkbox. Nothing really complex there.
Scanu
09-14-2012, 06:14 PM
Create a plugin and as hook choose userprofile_create
With this code
if ($this->userinfo['field16'] & 1)
$template_hook['headinclude_javascript'] .= 'your code fo fisrt option';
WorldCraft
09-14-2012, 08:00 PM
Doesn't appear to be doing anything. :(
Scanu
09-14-2012, 08:46 PM
Did you try the same code i posted above? Be sure to activate the plugin
WorldCraft
09-14-2012, 09:27 PM
Yeah, the plugin is active and the hook is set right. And for a test, I just tried an alert popup again, it doesn't run.
Scanu
09-14-2012, 09:43 PM
I'll try this as soon as i can to see what's the problem (i'm on mobile now)
WorldCraft
09-14-2012, 10:07 PM
Alright, thanks. Appreciate it.
Scanu
09-16-2012, 10:04 AM
Oh i'm sorry, i was sure i replied to this thread (maybe i had some problems with my connection).
This isn't the proper way to do this but at least it works!
if ($this->userinfo['field16'] & 1)
echo 'your code for fisrt option';
if ($this->userinfo['field16'] & 2)
echo 'your code for second option';
if ($this->userinfo['field16'] & 4)
echo 'your code for third option';
etc..
WorldCraft
09-17-2012, 01:21 AM
Seems to be working nicely, except in IE (not surprised). When I use IE the profile pages do not format correctly.
But thank you very much for the help. I'll work with this for now.
Edit: IE reports the error coming from vbulletin_textedit.js (for the Visitor Messaging postbox). My scripts do not seem to be the cause because trying a simple alert popup script will still cause the error in IE. So probably not much can be done about that.
Scanu
09-17-2012, 10:52 AM
Did you try to just put something like echo'test'; ?
WorldCraft
09-17-2012, 05:10 PM
Tried it, anything breaks it with IE.
Scanu
09-17-2012, 05:19 PM
Php is croos-browser since it runs in the server, maybe kh99 can help but i don't know why this error occurs :(
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.