Forums

Populate select from linked table

webcrea 30 Apr, 2015
I know do that in CF but Is it possible, very simply, populate a select from data's linked table?

In fact, when we have to use CF instead CC to manage our project?
webcrea 05 May, 2015
up
I have a table with honor
- id
- name
- image

and I would want to load it in a select in a form which manage the table users and honors named map_honor with :
- id
- user_id
- honor_id
- note

I create DB Read with
- multi-read, enable model id and fields = id,name
no relation, no db extern

And a dropdown field in chronoform form
- Field name and id = Honor_map[honor_id]
dynamic data enabled
- Value key = id
- Text key = name

nothing appears in the select, it seams I need something else :-)

thanks to all
chris
GreyHead 05 May, 2015
Hi webcrea,

Have you set a Model ID in the DB Read? you should set that to e.g. honour_map and then add honour_map to the Data Path box in the Dynamic Data tab of the Drop-down element.

Bob
webcrea 05 May, 2015
Thanks Bob,
That works fine in direct call from chronoform admin but not when when I call from "Edit" list(chronoconnectivity) ...??

Chris
webcrea 05 May, 2015
I try to define the front list same as admin list and I have this error message when I click view connection

Connection's name not present!

do you have an idea maybe?

thanks a lot
GreyHead 05 May, 2015
Hi chris,

I'm not sure why calling from CC would make a difference :-( But I'm not an expert in CCv5 by a long way.

If you add a Debugger to the form On Load event do you get any useful clues?

Bob
webcrea 05 May, 2015
I create an option menu to the connectivity list with connection name and the list is published well. But edit button opens the form without the dropdown filled !?
webcrea 07 May, 2015
Hello,

I think I reach the goal, I have the data fine in the data array but I can't populate the dropdown :

I would want id and username from [user]
Array
(
    [option] => com_chronoforms5
    [chronoform] => instructors-edit
    [0] => Array
        (
            [user] => Array
                (
                    [id] => 491
                    [username] => thewinekey
                )

            [cb] => Array
                (
                    [0] => Array
                        (
                            [id] => 491
                            [user_id] => 491
                            [firstname] => 
                            [middlename] => 
                            [lastname] => 

...etc


no error

somebody have an idea maybe
thanks a lot
chris
GreyHead 07 May, 2015
Hi chris,

I'm not clear what you have got here. The [0] makes it look as though it is an array without a name. That is going to be hard to work with. If you can give it a name like user_info then this custom code should pull out the data you need for your drop-down options.
<?php
$user_options = array();
foreach ($form->data['user_info'] as $u ) {
  $user_options[] = array( 'value' => $u['id'], 'text' => $u['username'] );
}
$form->data['user_options'] = $user_options[];
?>
Then you can set the Dynamic Options up with user_options, value, text.

Change the code to get the entries that you actually need rather than my guesses.

Bob
webcrea 07 May, 2015
hello bob and thanks to help me,

I'm agree with you, it's not clear for me too :-)

The result comes from a db read where users is the table master and comprofile a belongTo because I need a field "authorized_instructor" to load only some users. (25000 users)

In the db Model Id=user and fields id,username
I don't understand why there are indexed in data

I understand your solution I try it...
GreyHead 07 May, 2015
Hi chris,

Do you have a Model ID set in the DB Read - that should put the results in a named sub-array?

Bob
webcrea 07 May, 2015
that's work well...
Now I apply this faq http://www.chronoengine.com/faqs/72-ccv5/5208-connectivity-edit-with-chronoforms.html
the input text field were correctly informed but not the dropdown
In fact when I call the form directly the dropdown is ok and data are

Array
(
    [option] => com_chronoforms5
    [chronoform] => honors-edit
    [honor] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [nom] => Bordeaux
                )

            [1] => Array
                (
                    [id] => 2
                    [nom] => Champagne
                )

            [2] => Array
                (
                    [id] => 3
                    [nom] => Bourgogne
                )

            [3] => Array
                (
                    [id] => 4
                    [nom] => Rhône
                )

            [4] => Array
                (
                    [id] => 5
                    [nom] => Sud de France
                )

            [5] => Array
                (
                    [id] => 6
                    [nom] => Provence
                )

            [6] => Array
                (
                    [id] => 7
                    [nom] => Alsace
                )

        )

)
If I call the form from the list connected the dropdown is empty and data are not construct as the same
Array
(
    [option] => com_chronoconnectivity5
    [cont] => lists
    [ccname] => Honors
    [act] => edit
    [Itemid] => 1576
    [gcb] => 4
    [Honor_map] => Array
        (
            [id] => 4
            [honor_id] => 2
            [user_id] => 992
            [note] => 1.02
        )

    [User] => Array
        (
            [id] => 992
            [name] => xxx
            [username] => xxx
            [email] => xxx
            [password] => xxx
            [block] => 0
            [sendEmail] => 0
            [registerDate] => 2006-07-11 00:00:00
            [lastvisitDate] => 2007-02-08 00:00:00
            [activation] => 
            [params] => Array
                (
                    [update_cache_list] => 1
                    [admin_language] => 
                    [language] => 
                    [editor] => 
                    [helpsite] => 
                    [timezone] => 
                )

            [lastResetTime] => 0000-00-00 00:00:00
            [resetCount] => 0
            [otpKey] => 
            [otep] => 
            [requireReset] => 0
        )

    [Honor] => Array
        (
            [id] => 2
            [nom] => Champagne
            [image] => awardfws-champagne.png
        )

    [Comprofiler] => Array
        (
            [id] => 992
            [user_id] => 992
            [firstname] => 
            [middlename] => 
            [lastname] => 
            [hits] => 3
            [message_last_sent] => 0000-00-00 00:00:00
            [message_number_sent] => 0
            [avatar] => 
            [avatarapproved] => 1
            [canvas] => 
            [canvasapproved] => 1
            [approved] => 1
            [confirmed] => 1
            [lastupdatedate] => 0000-00-00 00:00:00
            [registeripaddr] => 
            [cbactivation] => 
            [banned] => 0
            [banneddate] => 
            [unbanneddate] => 
            [bannedby] => 
            [unbannedby] => 
            [bannedreason] => 
            [acceptedterms] => 0
            [cb_subs_inv_first_name] => 
            [cb_subs_inv_last_name] => 
            [cb_subs_inv_payer_business_name] => 
            [cb_subs_inv_address_street] => 
            [cb_subs_inv_address_city] => 
            [cb_subs_inv_address_state] => 
            [cb_subs_inv_address_zip] => 
            [cb_subs_inv_address_country] => 
            [cb_subs_inv_contact_phone] => 
            [cb_subs_inv_vat_number] => 
            [cb_folderaccess] => 
            [cb_fws_authorized_instructor] => 0
            [cb_bio] => 
            [cb_awards_obtained_dyn] => 0
        )

    [honor] => Array
        (
            [0] => 
            [1] => 
            [2] => 
            [3] => 
            [4] => 
            [5] => 
            [6] => 
        )

)

Maybe I lost something...??
webcrea 07 May, 2015
In the same time :-))
webcrea 07 May, 2015
The data were there and my question is, a form can be call directly and from a connection list and work correctly or I have to choose to construct 2 forms
GreyHead 08 May, 2015
Hi webcrea,

Sorry but I don't understand your question :-(

Bob
webcrea 08 May, 2015
Hello bob,

sorry for my english. The form works alone but not when I call it from a list (_EDIT_). The input text field were correctly informed but not the dropdown. All the dropdown are empty. I don't understand why. You can see the $form->data in my previous post

thanks
chris
GreyHead 09 May, 2015
Hi webcrea,

I still find this hard to understand. How are you loading the honor array when the form loads from the EDIT link? It looks as though the DB Read is finding no results in this case?

Bob
webcrea 11 May, 2015
1 Likes
Hello Bob,
I found it, there was a conflict with name :-((
I named honor options honor_opt and it works
thanks for your help
chris
This topic is locked and no more replies can be posted.