Use JHTML to create Multiple Select box

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
babberoo
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Wed Jan 23, 2008 5:35 pm

Use JHTML to create Multiple Select box

Post by babberoo » Mon Oct 06, 2008 1:33 pm

I have the following code in a custom component.

Code: Select all

<div class="formrow">
		<?php echo JHTML::_('select.genericlist',  $this->countries, 'countries_of_interest', 'class="inputbox" multiple size="8"', 'id', 'title'); ?>
	</div>
This populates the select list with countries from the database, which are available to be multiple selections. However, on submission, I'm only getting one value in my querystring and not an array of values. What am I missing?

babberoo
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Wed Jan 23, 2008 5:35 pm

Re: Use JHTML to create Multiple Select box

Post by babberoo » Mon Oct 06, 2008 2:27 pm

Sorted:

Code: Select all

<?php echo JHTML::_('select.genericlist',  $this->countries, 'countries_of_interest[]', 'class="inputbox" multiple="multiple" size="8"', 'id', 'title'); ?>
Note the [] at the end of the countries_of_interest.

I then implode my string to store in the database using:

$userdetails['countries_of_interest'] = implode(",", $userdetails['countries_of_interest']);

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: Use JHTML to create Multiple Select box

Post by AmyStephen » Thu Sep 03, 2009 4:48 pm

Thank you!

soulman411
Joomla! Apprentice
Joomla! Apprentice
Posts: 24
Joined: Tue Mar 16, 2010 2:34 am

Re: Use JHTML to create Multiple Select box

Post by soulman411 » Wed Apr 13, 2011 4:07 pm

in an edit scenario, how do you set values for a multi-select box using JHTML?

User avatar
vivec
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 143
Joined: Thu Jul 28, 2011 9:54 am

Re: Use JHTML to create Multiple Select box

Post by vivec » Sun Oct 30, 2011 2:20 pm

for the ones coming past this topic, the answer is:

Code: Select all

explode(',',JRequest::getVar('country_ids'))
This converts the post-variable 'country_ids' into an array.
Your URL should be:

http://www.yourwebsite.com/index.php?op ... ,2,7,34,75

To quote the (now updated) example:

Code: Select all

<?php echo JHTML::_('select.genericlist',  $this->countries, 'countries_of_interest[]', 'class="inputbox" multiple="multiple" size="8"', 'id', 'title', explode(',',JRequest::getVar('country_ids'))); ?>


Locked

Return to “General Questions/New to Joomla! 1.5”