Forums

Load data into form field (CF5)

nbento 23 Apr, 2015
Hi,

I' want do upload data from a bd table into my form. I read the FAQ (http://www.chronoengine.com/faqs/70-cfv5/5219-how-to-load-record-data-from-a-database-table-into-your-form.html) but I'm still width doubts.

This is what I have:
1. Two fields ("name" and "email_to") with the same name as the database;
2. "DB Read" action, just place it in your "on load" event and placed ABOVE the "HTML Render form" ;
3. Select de table "contact_details" and selected "No" in "Enable Model ID;
4. In the condictions box i have:
<?php
$user = JFactory::getUser();
return array('user_id' => $user->id);
return array("name" => $form->data("name"));
return array("email_to" => $form->data("email_to"));
?>

But the data are not loaded to the form, what is wrong?

Thanks
GreyHead 23 Apr, 2015
Hi nbento,

Only the first of your three return lines will be used but that should work OK to get the record fro that user_id.

Please drag a Debugger action into the On Load event, then submit the form and post the debug results here.

Bob
nbento 23 Apr, 2015
Here is the debuug results:

Array
(
    [option] => com_chronoforms5
    [chronoform] => Editar_dados
    [0] => Array
        (
            [id] => 429
            [name] => Iva Carla Fernandes Vieira
            [alias] => icv
            [con_position] => 
            [address] => 
            [suburb] => 
            [state] => 
            [country] => 
            [postcode] => 
            [telephone] => 53102
            [fax] => C203
            [misc] => 
            [image] => images/contactos/Iva Vieira.jpg
            [email_to] => ivavieira@eseig.ipp.pt
            [default_con] => 0
            [published] => 1
            [checked_out] => 0
            [checked_out_time] => 0000-00-00 00:00:00
            [ordering] => 54
            [params] => {"show_contact_category":"","show_contact_list":"","presentation_style":"","show_tags":"","show_name":"","show_position":"","show_email":"","show_street_address":"","show_suburb":"","show_state":"","show_postcode":"","show_country":"","show_telephone":"","show_mobile":"","show_fax":"","show_webpage":"","show_misc":"","show_image":"","allow_vcard":"","show_articles":"","show_profile":"","show_links":"","linka_name":"","linka":false,"linkb_name":"","linkb":false,"linkc_name":"","linkc":false,"linkd_name":"","linkd":false,"linke_name":"","linke":false,"contact_layout":"","show_email_form":"","show_email_copy":"","banned_email":"","banned_subject":"","banned_text":"","validate_session":"","custom_reply":"","redirect":""}
            [user_id] => 161
            [catid] => 284
            [access] => 1
            [mobile] => 
            [webpage] => 
            [sortname1] => 
            [sortname2] => 
            [sortname3] => 
            [language] => pt-PT
            [created] => 2011-11-29 15:42:52
            [created_by] => 191
            [created_by_alias] => 
            [modified] => 2015-04-21 14:18:09
            [modified_by] => 191
            [metakey] => 
            [metadesc] => Dados de contato de Iva Carla Fernandes Vieira
            [metadata] => {"robots":"","rights":""}
            [featured] => 0
            [xreference] => 
            [publish_up] => 0000-00-00 00:00:00
            [publish_down] => 0000-00-00 00:00:00
            [version] => 4
            [hits] => 31
        )

    [1] => Array
        (
            [id] => 553
            [name] => Iva Carla Fernandes Vieira
            [alias] => icv
            [con_position] => 
            [address] => 
            [suburb] => 
            [state] => 
            [country] => 
            [postcode] => 
            [telephone] => 53102
            [fax] => C202
            [misc] => 
            [image] => images/contactos/Iva Vieira.jpg
            [email_to] => ivavieira@eseig.ipp.pt
            [default_con] => 0
            [published] => 1
            [checked_out] => 0
            [checked_out_time] => 0000-00-00 00:00:00
            [ordering] => 55
            [params] => {"show_contact_category":"","show_contact_list":"","presentation_style":"","show_tags":"","show_name":"","show_position":"","show_email":"","show_street_address":"","show_suburb":"","show_state":"","show_postcode":"","show_country":"","show_telephone":"","show_mobile":"","show_fax":"","show_webpage":"","show_misc":"","show_image":"","allow_vcard":"","show_articles":"","show_profile":"","show_links":"","linka_name":"","linka":false,"linkb_name":"","linkb":false,"linkc_name":"","linkc":false,"linkd_name":"","linkd":false,"linke_name":"","linke":false,"contact_layout":"","show_email_form":"","show_email_copy":"","banned_email":"","banned_subject":"","banned_text":"","validate_session":"","custom_reply":"","redirect":""}
            [user_id] => 161
            [catid] => 285
            [access] => 1
            [mobile] => 
            [webpage] => 
            [sortname1] => 
            [sortname2] => 
            [sortname3] => 
            [language] => en-GB
            [created] => 2011-11-29 15:42:52
            [created_by] => 191
            [created_by_alias] => 
            [modified] => 2015-04-22 11:11:03
            [modified_by] => 191
            [metakey] => 
            [metadesc] => Dados de contato de Iva Carla Fernandes Vieira
            [metadata] => {"robots":"","rights":""}
            [featured] => 0
            [xreference] => 
            [publish_up] => 0000-00-00 00:00:00
            [publish_down] => 0000-00-00 00:00:00
            [version] => 3
            [hits] => 18
        )

)
Array
(
)


Array
(
    [0] => Array
        (
            [DB Read] => Array
                (
                    [Queries] => Array
                        (
                            [0] => SELECT `Data`.`id` AS `Data.id`, `Data`.`name` AS `Data.name`, `Data`.`alias` AS `Data.alias`, `Data`.`con_position` AS `Data.con_position`, `Data`.`address` AS `Data.address`, `Data`.`suburb` AS `Data.suburb`, `Data`.`state` AS `Data.state`, `Data`.`country` AS `Data.country`, `Data`.`postcode` AS `Data.postcode`, `Data`.`telephone` AS `Data.telephone`, `Data`.`fax` AS `Data.fax`, `Data`.`misc` AS `Data.misc`, `Data`.`image` AS `Data.image`, `Data`.`email_to` AS `Data.email_to`, `Data`.`default_con` AS `Data.default_con`, `Data`.`published` AS `Data.published`, `Data`.`checked_out` AS `Data.checked_out`, `Data`.`checked_out_time` AS `Data.checked_out_time`, `Data`.`ordering` AS `Data.ordering`, `Data`.`params` AS `Data.params`, `Data`.`user_id` AS `Data.user_id`, `Data`.`catid` AS `Data.catid`, `Data`.`access` AS `Data.access`, `Data`.`mobile` AS `Data.mobile`, `Data`.`webpage` AS `Data.webpage`, `Data`.`sortname1` AS `Data.sortname1`, `Data`.`sortname2` AS `Data.sortname2`, `Data`.`sortname3` AS `Data.sortname3`, `Data`.`language` AS `Data.language`, `Data`.`created` AS `Data.created`, `Data`.`created_by` AS `Data.created_by`, `Data`.`created_by_alias` AS `Data.created_by_alias`, `Data`.`modified` AS `Data.modified`, `Data`.`modified_by` AS `Data.modified_by`, `Data`.`metakey` AS `Data.metakey`, `Data`.`metadesc` AS `Data.metadesc`, `Data`.`metadata` AS `Data.metadata`, `Data`.`featured` AS `Data.featured`, `Data`.`xreference` AS `Data.xreference`, `Data`.`publish_up` AS `Data.publish_up`, `Data`.`publish_down` AS `Data.publish_down`, `Data`.`version` AS `Data.version`, `Data`.`hits` AS `Data.hits` FROM `eseig_contact_details` AS `Data` WHERE `Data`.`user_id` = '161'
                        )

                )

        )

)
GreyHead 23 Apr, 2015
1 Likes
Hi nbento,

That looks as though it is working - except that you have two records for the same user_id. How do you plan to handle that situation? Maybe some house-keeping is required?

Bob
nbento 23 Apr, 2015
Yes, i have two records for each id, because my website is multilangue.
How could i filter by the user language, database field "language= pt-PT"?
nbento 23 Apr, 2015
I changed my condictions to:

<?php
$user = JFactory::getUser();
return array('user_id' => $user->id, 'language' => 'pt-PT' );
?>

But still nothing!!
nbento 23 Apr, 2015
Answer
1 Likes
Problem solved!!
Changed the field "Multi read" to "No" in DB Read action, and it works!!!!
Thanks GreyHead and calculus00 for the help!!!
This topic is locked and no more replies can be posted.