1
Mithrandir
Multiselect in preferences - how do I?

I'd like to use a multiple selection in my module preferences.

Making the multiselect doesn't seem to be a big problem - but how do I access the information afterwards?

The "normal" preferences is just $xoopsModuleConfig['name'] - but how do I access the multiple values?

2
phatjew
Re: Multiselect in preferences - how do I?
  • 2003/10/17 21:26

  • phatjew

  • Just popping in

  • Posts: 56

  • Since: 2003/10/8


This was a tricky one, but I figured it out for the reviews module that I am writing (possibly soon to be released).

First, you must understand that by putting a [] after the name of an input on a form, that makes it pass its value as an array. However, it also makes it difficult for javascript to see that element, so you want to start with the name of the list box NOT having the [].

1. go to:
http://javascript.internet.com/forms/form-swapper-2.html

and get the code (with javascript) for the menu swapper. This allows you to choose as many items as you want from one multiple select and move them to a second multiple select. I personally am using XOOPS 2.0.5, and I put the javascript here and below into xoops.js, since I use it on many pages. The definition of my second multiple select is as follows:


where review_categories is the name of my second multiple select, and "makeArray" looks like this:

function makeArray(tBox)
{
tBox.name=tBox.name + "[]";
for (i=0;i {
tBox.options[i].selected = true;
}
}

NOTE -- this is where the [] is added to the name of the input, making it pass the values as an array.

3. On the next page, you can access all the values of the input by using array syntax (review_categories[0], review_categories[1], etc., in my case).

Hope this helps.

--Rafi

3
onokazu
Re: Multiselect in preferences - how do I?
  • 2003/10/17 21:37

  • onokazu

  • XOOPS Founder

  • Posts: 617

  • Since: 2001/12/13


What did you define for the $modversion[config][][options] directive?
If it is something like this:

$modversion[config][][options] = array('1st option' => 1, '2nd option' => 2, '3rd option' => 3);

and you have selected the '1st option' and '2nd option' options in the module preferences, then $xoopsModuleConfig[name] should be an array containing values 1 and 2.

4
Mithrandir
Re: Multiselect in preferences - how do I?

Thanks for a very fast reply.

I've tried this:
//Preferences
$modversion['config'][1]['name'] = 'selected_sections';
$modversion['config'][1]['title'] = '_MI_TEAM_SECTIONS';
$modversion['config'][1]['description'] = '_MI_TEAM_SECTIONSDESC';
$modversion['config'][1]['formtype'] = 'select multi';
$modversion['config'][1]['valuetype'] = 'array';
$modversion['config'][1]['default'] = array(123456);
$modversion['config'][1]['options'] = array('Tactics' => 1'Matches' => 2'Availability' => 3'Positions' => 4'Stats' => 5'Player Profiles' => 6);


and get this error message:
Warninghtmlspecialchars() expects parameter 1 to be string, array given in /usr/local/psa/home/vhosts/ruffdesigns.co.uk/web_users/Mithrandir/class/module.textsanitizer.php on line 252

5
Mithrandir
Re: Multiselect in preferences - how do I?

Nobody's been using those before?

Anyone able to build on top of Kazu's explanation? It would really rock to have multi-selects in my preferences.

6
Mithrandir
Re: Multiselect in preferences - how do I?

How nice. A built-in functionality, which is impossible to use. I know the documentation of XOOPS is being worked on... but geez, come on. Surely SOMEONE must have used this before. Someone has programmed it... But still, noone able to explain how to use it... That's just great. Really motivating.

I'm sorry, but I've had enough of trial-and-error programming until I accidently find the right method or syntax. I'm also tired of digging through classes, include files, extra functions etc. to find simple answers to simple problems.

So someone with knowledge, please? Is it too much to ask?

7
onokazu
Re: Multiselect in preferences - how do I?
  • 2003/10/20 12:01

  • onokazu

  • XOOPS Founder

  • Posts: 617

  • Since: 2001/12/13


what do you get when you do

print_r($xoopsModuleConfig['name']);

8
Mithrandir
Re: Multiselect in preferences - how do I?

Array ( [0] => )


But I can't set it in the preferences, that's the problem.
I get the preference showing up with description and all - but the multi-select is not a select box, but a text line and I get the

Warning: htmlspecialchars() expects parameter 1 to be string, array given in [....]/class/module.textsanitizer.php on line 252

On top of the page.

(Sorry for blowing up like that, but it's just so frustrating that this functionality, which should make my life so easy is not working as I expected it)

9
onokazu
Re: Multiselect in preferences - how do I?
  • 2003/10/20 13:36

  • onokazu

  • XOOPS Founder

  • Posts: 617

  • Since: 2001/12/13


Do you really have the formtype directive set as below?
See if you have the underscore line between 'select' and 'multi'.

$modversion['config'][1]['formtype'] = 'select_multi';


10
Mithrandir
Re: Multiselect in preferences - how do I?

Hummm - due to PHPCoder's way of displaying comments, the underscore was not visible, so I had only 'select multi'

Thanks - it's working now, except for the default values... but that's a minor problem.

Login

Who's Online

284 user(s) are online (191 user(s) are browsing Support Forums)


Members: 0


Guests: 284


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits