Problem with option multiple="multiple" for sql form field type

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
venci
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Nov 17, 2012 6:10 am

Problem with option multiple="multiple" for sql form field type

Post by venci » Tue Jan 16, 2018 1:40 pm

I want to display module content on selected articles only
This is my php code for Joomla module

Code: Select all

$selectarticle  = $params->get('selectarticle');
$article_id = JRequest::getInt( 'id' );

if ( $article_id == $selectarticle ) {    
// my code
 }
and code in xml file

Code: Select all

<field
    name="selectarticle"
    type="sql"
    default="10"
    multiple="multiple"
    label="Select an article"
    query="SELECT id, title FROM #__content"
    key_field="id"
    value_field="title"
    />
Unfortunately, nothing happens


If changes the code in xml file of this

Code: Select all

<field
    name="selectarticle"
    type="sql"
    default="10"
    label="Select an article"
    query="SELECT id, title FROM #__content"
    key_field="id"
    value_field="title"
    />
Now I can choose only one article and the content is displayed when reviewing this article
The problem is how to make the content be displayed on more than one article

Any help will be highly appreciated!

User avatar
pmleconte
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 155
Joined: Fri Mar 17, 2017 12:55 pm

Re: Problem with option multiple="multiple" for sql form field type

Post by pmleconte » Tue Jan 16, 2018 5:49 pm

Hi,

I think the correct syntax is multiple="true", documentation https://docs.joomla.org/SQL_form_field_type seems to be wrong.

Pascal

PS: you may see this syntax in modules/mod_articles_category/mod_article_category.xml (line 195 : created_by_alias field)
If anything can go wrong, it will.
https://www.conseilgouz.com/en

venci
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Nov 17, 2012 6:10 am

Re: Problem with option multiple="multiple" for sql form field type

Post by venci » Wed Jan 17, 2018 8:11 am

Hi Pascal,
Thanks for your reply.
I have made changes according to your suggestion.
Unfortunately I do not get the result I expect.

User avatar
pmleconte
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 155
Joined: Fri Mar 17, 2017 12:55 pm

Re: Problem with option multiple="multiple" for sql form field type

Post by pmleconte » Wed Jan 17, 2018 8:26 am

Hi,

Could you copy your field description, so I can test it ?

Pascal
If anything can go wrong, it will.
https://www.conseilgouz.com/en

venci
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Nov 17, 2012 6:10 am

Re: Problem with option multiple="multiple" for sql form field type

Post by venci » Wed Jan 17, 2018 8:32 am

This is the code of xml file

Code: Select all

<field
    name="selectarticle"
    type="sql"
    size="5"
    default="10"
    multiple="true"
    label="Select an article"
    query="SELECT id, title FROM #__content"
    key_field="id"
    value_field="title"
    />

User avatar
pmleconte
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 155
Joined: Fri Mar 17, 2017 12:55 pm

Re: Problem with option multiple="multiple" for sql form field type

Post by pmleconte » Wed Jan 17, 2018 8:47 am

Just tried your field and seems to be ok
multiple.jpg
Pascal
You do not have the required permissions to view the files attached to this post.
If anything can go wrong, it will.
https://www.conseilgouz.com/en

venci
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Nov 17, 2012 6:10 am

Re: Problem with option multiple="multiple" for sql form field type

Post by venci » Wed Jan 17, 2018 9:09 am

Hi Pascal,
Thanks for your efforts and I appreciate them highly

Yes. As an administrator I can choose more than one article.
But the reply does not return the ID of the selected articles.
If I remove the code

Code: Select all

multiple="true"
Returns the ID of the selected article.

I may be mistaken, but I think if I choose more than one article, I have to get the ID of the all selected articles

User avatar
pmleconte
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 155
Joined: Fri Mar 17, 2017 12:55 pm

Re: Problem with option multiple="multiple" for sql form field type

Post by pmleconte » Wed Jan 17, 2018 9:28 am

It returns an array of selected ids

You could do

$articles = $params->get('selectarticle');
then
foreach ($articles as $article) to retrieve each id.

Pascal
If anything can go wrong, it will.
https://www.conseilgouz.com/en

venci
Joomla! Apprentice
Joomla! Apprentice
Posts: 46
Joined: Sat Nov 17, 2012 6:10 am

Re: Problem with option multiple="multiple" for sql form field type

Post by venci » Wed Jan 17, 2018 9:58 am

Hi Pascal,
Many thanks for your time and effort.
Your help is highly appreciated.
Thank!!!


Post Reply

Return to “Joomla! 3.x Coding”