Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
[How-to] Add a multiselect field in vBulletin options
Coroner
Join Date: Feb 2008
Posts: 797

I start for about 25 years with an TI and learned Basic. Next was an Commodere 64, Amiga. On Amiga I learned Assembler and wrote some Games. Many years later again, I learned myself (without book ...) php,html and javascript. Then I wrote some small

Germany
Show Printable Version Email this Page Subscription
Coroner Coroner is offline 09-22-2008, 10:00 PM

I wrote this article 'cause I didn't found anything else but it was needed for mod I wrote.

Before I start - will have to say this is an example for a forumchooser.

In our product under options, create an option like this:
PHP Code:
<setting varname="your_setting_varname" displayorder="1">
 <
datatype>free</datatype>
 <
optioncode>multiselect:eval
$options construct_forum_chooser_options(1);</optioncode>
 <
defaultvalue>0</defaultvalue>
</
setting
I'll use: multiselect:eval.

Ok, we finished our first part and need 2 new plugins.

The first plugin we used is admin_options_print.
PHP Code:
    <plugin active="1" product="yourproduct">
      <
title>expand options for multiselect</title>
      <
hookname>admin_options_print</hookname>
      <
phpcode><![CDATA[if (preg_match ('#^(multiselect):(eval)(\r\n|\n|\r)(.*)$#siU'$setting['optioncode'], $matches))
{
 
$options null;
 eval (
$setting['optiondata']);
 
// this is for multiselect options
 
$title $description;
 
$array construct_forum_chooser_options (0);
 
$selected explode (','$setting['value']);
 
$name .= "[]";
 
$htmlise 0;
 
$size 10;
 
$multiple true;
 global 
$vbulletin;
 
$uniqueid fetch_uniqueid_counter ();
 
$select "<div id=\"ctrl_$name\"><select name=\"$name\" id=\"sel_{$name}_$uniqueid\" tabindex=\"1\" class=\"bginput\"" iif($size" size=\"$size\"") . iif($multiple' multiple="multiple"') . iif($vbulletin->debug" title=\"name=&quot;$name&quot;\"") . ">\n";
 
$select .= construct_select_options ($array$selected$htmlise);
 
$select .= "</select></div>\n";
 
print_label_row ($title$select'''top'$name);
 
$handled true;
}]]></
phpcode>
    </
plugin
See the code above and take a look at this three lines:
$array = construct_forum_chooser_options (0);
$selected = explode (',', $setting['value']);
$name .= "[]";
The 1st line are our options array, filled with information coming from the function "construct_forum_chooser_options(0)". If you wanna have your own, create an array with your options.
2nd line: our value (saved later in the options will implode by a comma like: 5,8,11,26,.. we need to explode this value to get the selected values back.
3rd line: this is needed for multiselect

The next plugin is called: admin_options_processing.
PHP Code:
<plugin active="1" product="yourproduct">
      <
title>save our multiselect values</title>
      <
hookname>admin_options_processing</hookname>
      <
phpcode><![CDATA[
if (
preg_match ('/multiselect/i'$oldsetting['optioncode']))
{
 if (
is_array ($settings["$oldsetting[varname]"])) $settings["$oldsetting[varname]"] = implode (','$settings["$oldsetting[varname]"]);
}]]></
phpcode>
    </
plugin
This plugin will implode our selected values with a comma.

Regards
Reply With Quote
  #2  
Old 10-10-2008, 04:38 PM
Stoebi Stoebi is offline
 
Join Date: Apr 2006
Location: Germany, Berlin
Posts: 331
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This is great. Thank you very much for sharing


Regards,

Stoebi
Reply With Quote
  #3  
Old 10-28-2008, 01:52 PM
Blackhat's Avatar
Blackhat Blackhat is offline
 
Join Date: Mar 2005
Posts: 323
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

can this be used in the user cp > options to make a "forum chooser" and which hook should I use?
Reply With Quote
  #4  
Old 11-24-2008, 08:31 AM
ReCom ReCom is offline
 
Join Date: Mar 2008
Posts: 97
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

A setting with datatype "bitfield" can create a group of checkboxes (multiselection) in vBulletin Options.
Reply With Quote
  #5  
Old 07-18-2009, 08:14 AM
Coroner Coroner is offline
 
Join Date: Feb 2008
Location: Germany
Posts: 797
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I didn't mean a forumchooser (Selectrow) or a multiple checkbox.

See image for the "multiselect field" what I mean.
Attached Images
File Type: jpg Bild 1.jpg (34.1 KB, 0 views)
Reply With Quote
  #6  
Old 10-09-2013, 12:07 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The chooser code is great but i am unsure how to call it in a plug in, normally i'd have the user enter the forum id's and use something like $allowedforums = explode(",", $vbulletin->options['sens_forumid']);
if (in_array($threadinfo['forumid'], $allowedforums))

How do i use the information of the selected forums creating a multiselect like this?
Reply With Quote
  #7  
Old 10-09-2013, 12:13 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I believe what you are after is something this.

Code:
    if(in_array($GLOBALS['forumid'], explode(',', $vbulletin->options['MY_OPTION_NAME'])))
    {
       Your Code Here
    }
Reply With Quote
  #8  
Old 10-09-2013, 12:14 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That works with the above?
Reply With Quote
  #9  
Old 10-09-2013, 12:17 AM
ozzy47's Avatar
ozzy47 ozzy47 is offline
 
Join Date: Jul 2009
Location: USA
Posts: 10,929
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It should, the code I provided, works in my mods that I have a forum chooser in options, via a multi select field.
Reply With Quote
  #10  
Old 10-09-2013, 12:23 AM
Simon Lloyd's Avatar
Simon Lloyd Simon Lloyd is offline
 
Join Date: Aug 2008
Location: Manchester
Posts: 3,481
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmm, i tried a variation of the code i provided and it didnt work, the code you provided gives an error
Quote:
Parse error: syntax error, unexpected T_IF in /home/thecodec/public_html/forumz/showthread.php(112) : eval()'d code on line 31
--------------- Added [DATE]1381281909[/DATE] at [TIME]1381281909[/TIME] ---------------

Errrr.....ummmm, guess who added an extra F to his own IF function!!!

My apologies!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:53 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.10046 seconds
  • Memory Usage 2,338KB
  • Queries Executed 24 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)bbcode_code
  • (3)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (1)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (9)postbit
  • (1)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete