The Joomla! Forum ™



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.



Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Mon Oct 06, 2008 1:33 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Wed Jan 23, 2008 5:35 pm
Posts: 139
I have the following code in a custom component.

Code:
<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?


Top
 Profile  
 
PostPosted: Mon Oct 06, 2008 2:27 pm 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Wed Jan 23, 2008 5:35 pm
Posts: 139
Sorted:

Code:
<?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']);


Top
 Profile  
 
PostPosted: Thu Sep 03, 2009 4:48 pm 
Joomla! Champion
Joomla! Champion

Joined: Wed Nov 22, 2006 3:35 pm
Posts: 7056
Location: Nebraska
Thank you!

_________________
http://Twitter.com/AmyStephen
http://www.alltogetherasawhole.org/


Top
 Profile  
 
PostPosted: Wed Apr 13, 2011 4:07 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Mar 16, 2010 2:34 am
Posts: 24
in an edit scenario, how do you set values for a multi-select box using JHTML?


Top
 Profile  
 
PostPosted: Sun Oct 30, 2011 2:20 pm 
User avatar
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Thu Jul 28, 2011 9:54 am
Posts: 143
for the ones coming past this topic, the answer is:

Code:
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?option=com_yourcomponent&country_ids=1,2,7,34,75

To quote the (now updated) example:

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 



Who is online

Users browsing this forum: No registered users and 33 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group