PDA

View Full Version : Tickbox vB Option Code


Kirk Y
07-01-2006, 04:12 AM
Trying to setup a vb option setting with tick boxes in it. I took some code from a setting that already had them and implemented it into my own, but now I'm getting this wacky error:

Fatal error: Unsupported operand types in \includes\adminfunctions_options.php on line 229


This is the code I'm using:

<fieldset>
<legend>options</legend>
<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"0\" />
<div class=\"smallfont\"><label for=\"option1\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" value=\"1\" id=\"option1\" " . iif(bitwise($setting['value'], 1), 'checked="checked"') . " /><b>option 1</b></label></div>
<div class=\"smallfont\"><label for=\"option2\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" value=\"2\" id=\"option2\" " . iif(bitwise($setting['value'], 2), 'checked="checked"') . " /><b>option 2</b></label></div>
</fieldset>

What am I missing here? TIA for any help.

Adrian Schneider
07-01-2006, 06:43 AM
Set the datatype to free.

Kirk Y
07-01-2006, 02:40 PM
Yeah I tried that, but then it won't save the status of the tickboxes. Same with Boolean.

Kirk Y
07-03-2006, 02:54 AM
Does anyone else have an idea?

Adrian Schneider
07-03-2006, 03:19 AM
You need to convert the data to an integer first, then upon retrieving the data, check to see the individual values. Bitfields make it easy....

admin_options_processing hook:

if ($oldsetting['varname'] == 'yourvarname')
{
$bitfield = 0;
foreach ($vbulletin->GPC['setting'][$oldsetting['varname']] AS $bitval)
{
$bitfield += $bitval;
}
$vbulletin->GPC['setting'][$oldsetting['varname']] = $bitfield;
}Okay, now that it is an integer...

option eval code
<fieldset>
<legend>$vbphrase[yes] / $vbphrase[no]</legend>
<input type=\"hidden\" name=\"setting[$setting[varname]][]\" value=\"0\" />
<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
<tr valign=\"top\">
<td class=\"smallfont\" nowrap=\"nowrap\">
<label for=\"yoursetting1\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting1\" value=\"1\" tabindex=\"1\" " . iif(bitwise($setting['value'], 1), 'checked="checked"') . " />Ratings</label><br />
<label for=\"yoursetting2\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting2\" value=\"2\" tabindex=\"1\" " . iif(bitwise($setting['value'], 2), 'checked="checked"') . " />Entries</label><br />
<label for=\"yoursetting4\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting4\" value=\"4\" tabindex=\"1\" " . iif(bitwise($setting['value'], 4), 'checked="checked"') . " />Last Entry</label><br />
<label for=\"yoursetting8\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting8\" value=\"8\" tabindex=\"1\" " . iif(bitwise($setting['value'], 8), 'checked="checked"') . " />Comments</label><br />
<label for=\"yoursetting16\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting16\" value=\"16\" tabindex=\"1\" " . iif(bitwise($setting['value'], 16), 'checked="checked"') . " />Last Comments</label><br />
<label for=\"yoursetting32\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting32\" value=\"32\" tabindex=\"1\" " . iif(bitwise($setting['value'], 32), 'checked="checked"') . " />Views</label><br />
<label for=\"yoursetting64\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting64\" value=\"64\" tabindex=\"1\" " . iif(bitwise($setting['value'], 64), 'checked="checked"') . " />Category</label><br />
<label for=\"yoursetting128\"><input type=\"checkbox\" name=\"setting[$setting[varname]][]\" id=\"yoursetting128\" value=\"128\" tabindex=\"1\" " . iif(bitwise($setting['value'], 128), 'checked="checked"') . " />Mass Moderation</label><br />
</td>
</tr>
</table>
</fieldset>

^ should give you an idea

Kirk Y
07-03-2006, 04:48 PM
Thanks SirAdrian, I'll try that later.

Is there a reason that you've got the setting increments doubling?

Adrian Schneider
07-03-2006, 06:59 PM
Here's a visual explanation...
http://www.litfuel.net/tutorials/images/800binary.gif

Kirk Y
07-03-2006, 07:27 PM
Ha ha -- thanks SirAdrian, that makes sense.

One final question before the thread can be put to bed: how do I call the option?

The typical $vbulletin->options[varname] returns an array, go figure, but I'm not sure what values to use for each bit.

Adrian Schneider
07-03-2006, 07:35 PM
I have this in my PHP file where I use it var $parsingLookup = array(
'html' => 1,
'smilies' => 2,
'bbcode' => 4,
'images' => 8,
'lines' => 16
);$entryParsing = convert_bits_to_array($blog->option('parse_entry'), $blog->parsingLookup);
$entry['body'] = $parser->do_parse($entry['body'],
$entryParsing['html'],
$entryParsing['smilies'],
$entryParsing['bbcode'],
$entryParsing['images'],
$entryParsing['lines'],
false
);

^ an example

For the values, go up by multiples of two (binary!), then make sure the values you use matchup with an array (in my case, $blog->parsingLookup).

Kirk Y
07-03-2006, 07:44 PM
Thanks again for all your help and the laugh :p, I've got everything working perfectly.