Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7035209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:16:39+00:00 2026-05-28T01:16:39+00:00

In my joomla custom component I used the SQL field type (item.xml): <field name=colors

  • 0

In my joomla custom component I used the SQL field type (item.xml):

    <field name="colors" type="sql" query="SELECT id ,name FROM #__products_colors" multiple="multiple" key_field="id" value_field="name" class="inputbox"
         label="colors" description="COM_PRODUCTS_FORM_DESC_ITEM_COLORS" /> 

In my view I call the field like this:

<?php echo $this->form->getInput('colors'); ?>

Which gives me a nice and smooth selectbox like this:

<select id="jform_colors" class="inputbox" multiple="multiple" name="jform[colors][]" aria-invalid="false">
<option value="1">blue</option>
<option value="2">yellow</option>
<option value="3">red</option>
<option value="4">green</option>
<option value="5">purple</option>

When I save this colors field, after selecting blue and red for example it gets saved as 1,3 in my database. Joomla does all the work for me… (THANKS Joomla)

Now maybe I am getting greedy, but somehow I expect Joomla to preselect these values for me when I edit an entry after saving. It does this with every other type of field, so why not here? Is there anything Im forgetting?

Thanks in adv!

edit: the bind function in the answer, I tweaked it a bit.

    public function bind($array, $ignore = '') {
    if (isset($array['params']) && is_array($array['params'])) {
        $registry = new JRegistry();
        $registry->loadArray($array['params']);
        $array['params'] = (string) $registry;
    }
    //print_r($array);
    if (key_exists('colors', $array) && is_array($array['colors'])) {
        echo "pwn";
        $array['colors'] = implode(',', $array['colors']);
    }

    if (isset($array['metadata']) && is_array($array['metadata'])) {
        $registry = new JRegistry();
        $registry->loadArray($array['metadata']);
        $array['metadata'] = (string) $registry;
    }
    return parent::bind($array, $ignore);
}

And DONT use filter=”safehtml” 🙂

Good luck all!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:16:39+00:00Added an answer on May 28, 2026 at 1:16 am

    If you are following Joomla’s standards, you should have a method called “loadFormData” in your model. There you can be sure that the field is converted to array when fetched from the database, example:

    <?php
    protected function loadFormData()
    {
        // Check the session for previously entered form data.
        $data = JFactory::getApplication()->getUserState('com_yourcomponent.edit.item.data', array());
    
        if (empty($data)) {
            $data = $this->getItem();
        }
    
        // THIS IS WHAT YOU MUST BE MISSING
        if (is_array($data) && !is_array($data['colors'])){
            $data['colors'] = explode(',',$data['colors']);
        } elseif (is_object($data) && !is_array($data->colors)) {
            $data->colors = explode(',',$data->colors);
        }
    
        return $data;
    }
    ?>
    

    You will also need to override your bind method in your table class:

    <?php
    public function bind($src, $ignore = array())
    {
        if (parent::bind($src, $ignore) && is_array($this->colors)){
            $this->colors = implode(',', $this->colors);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom Joomla component and a router for building my SEF URL's
I'm trying to create a custom registration component for Joomla, and I was wondering
I'm planning on developing a Joomla custom component and storing the files in a
I have generated an rss feed in my custom component in my joomla site.
I'm using Joomla Framework to create component that displays options from a MySQL table.
I'm using Joomla 1.5. I have created a custom component that pulls data out
I am using Joomla 1.5 . I have developed a custom component that's basically
I develop a custom joomla 1.5 component and it's working fine locally(wamp server ,php
I am working on a custom Joomla MVC component. My view has a form
I have created custom component and a route plugin for Joomla 1.5 to to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.