Problem with Picklist element when saving form

herve06

Member
Hello,

I have a problem when I want to save a form with a picklist element.

I have populated the picklist with php code like in the example :

$db = FabrikWorker::getDbo(false, 6);
$db->setQuery("SELECT CODE, NAME FROM t_table ");
$rows = $db->loadObjectList();
foreach ($rows as $row) {
$options[] = JHTML::_('select.option', $row->CODE, $row->NAME);
}
return $options;


When I fill the form, the picklist is displayed correctly and I can drag elements from thr FROM list to the TO list.
However, when I save the form I have an error because instead of saving the CODE(s) of the selected option(s) it is trying to save the symbol "[".
upload_2015-12-10_15-32-24.png

Does someone has any idea of why I have this ? What could be my mistake or what did I forgot or missed ?

Thank you in advance for your help.
 
Picklist seems to be not working at the moment.
With standard suboptions it's also saving "[" only.

But I think in your case the main error is "Duplicate ...PRIMARY".
Don't use the standard variable names in your code, this may override used Fabrik or Joomla variables, so do
$mydb = ...
$mydb->setQuery... etc
$myrows....

and see if this error will be gone.
 
Right, thank you the error is gone now.
I now have a message saying the element has been saved/updated.
upload_2015-12-11_10-44-43.png
However, it's still not working because of this "[". As my field is numeric it's always saving "0" in my table.
So, there is no solution for the picklist for the moment ?
Do you know if there is another plugin equivalent to this one ?

Thanks.
 
Thanks a lot hugh, it's working now !
However, I still have problem when I select more than one element in the picklist.

Maybe I use it the wrong way but what I want to do is :

For each option selected in the TO list, save it in a new row with a specified code.
In my form I have 2 element :
1 internalid (CODE)
1 picklistl (ACTIVITY)
For example, if I select two activities in the picklist : 4-Sport and 7-Music (and the internalid is 11),
I should have 2 new rows in my list:
ACTIVITY CODE
4 11
7 11

For the moment it works only if I select one activity. If I select two activities (or more) it saves ACTIVITY=0.
Do you have an idea why it is not working ? Maybe I'm confusing with the way of using this element...
I also tried to use the upsert plugin of form or to write php code at the end of the form (to save "manually" in the table) but no concluant result...


Thanks for your help.
 
The picklist isn't a join element, it just saves a single field in a single row, as a JSON data array of the values. What field type is your 'activity' in the database? It should be a TEXT or a VARCHAR. I suspect it may be an INT if it's saving 0 for multiple selections.

-- hugh
 
Indeed, my 'activity' field is an INT.

So I guess I should use php code to save it in my database? Or do you have another suggestion?
 
I can see all kinds of potential problems trying to do that. The picklist just wasn't designed to work that way. And forms don't work that way either. Forms save to a single row, and only joined data can be "repeated", in separate, joined tables.

If you aren't married to the picklist, you could try using a join element in 'checkbox' mode, which automatically creates a many-to-many mapping table between your form's table and the joined table.

So if your form is 'yourform', and you have an 'activities' table with all the activity options, creating a checkbox join from yourform to activities would create a yourform_activities_repeat table, which would have id, activity )FK to activities table) and parent_id (FK to yourform).

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top