I have a form where users can update their own data which is stored in a db. How can I read the right db-values and load it into form-fields as default values?
The db-table I want to used is called jos_comprofiler, which has several fields like id, username, email, telephone. Id corresponds with the Joomla-userid.
In Chronoforms v4 I used the event DB Record Loader, where I opened table jos_comprofiler. DB Field was 'id' and in the advanced-tab I've added a PHP-where clause:
<?php
$user =& JFactory::getUser();
echo "`id` = '{$user->id}'";
?>
After this event, I could set default field values e.g. {username}.
How do I do this in Chronoforms v7?
You need a "Read Data" action in the form page, setup the where conditions and make sure the data is retrieved, you can use the form debug to check the read data
In the Read Data behaviors, make sure the "Populate fields" is enabled, your fields names should be in this format:
Read_data_model_name.table_field_name
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Hi Max,
The problem is how to use the WHERE condition. The table com_profiler contains all kinds of userdata, the field 'id' in this table corresponds with the id in the Joomla users-table. I want to select the userdata in table com_profiler corresponding to the current user-id, which (in CF4) I could find throughout the php-code I mentioned. I don't know how to do the same thing in CF7.
Hans
in v7 you can use {user:id} to get the user's id, so use that in the where condition value:
id = {user:id}
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
I've tried that. When I do that, the debugger result is:
SELECT `gebruiker`.`id` AS `gebruiker.id`, `gebruiker`.`user_id` AS `gebruiker.user_id`, `gebruiker`.`alias` AS `gebruiker.alias`, `gebruiker`.`firstname` AS `gebruiker.firstname`, `gebruiker`.`middlename` AS `gebruiker.middlename`, `gebruiker`.`lastname` AS `gebruiker.lastname`, `gebruiker`.`hits` AS `gebruiker.hits`, `gebruiker`.`message_last_sent` AS `gebruiker.message_last_sent`, `gebruiker`.`message_number_sent` AS `gebruiker.message_number_sent`, `gebruiker`.`avatar` AS `gebruiker.avatar`, `gebruiker`.`avatarapproved` AS `gebruiker.avatarapproved`, `gebruiker`.`canvasapproved` AS `gebruiker.canvasapproved`, `gebruiker`.`canvasposition` AS `gebruiker.canvasposition`, `gebruiker`.`canvas` AS `gebruiker.canvas`, `gebruiker`.`approved` AS `gebruiker.approved`, `gebruiker`.`confirmed` AS `gebruiker.confirmed`, `gebruiker`.`lastupdatedate` AS `gebruiker.lastupdatedate`, `gebruiker`.`registeripaddr` AS `gebruiker.registeripaddr`, `gebruiker`.`cbactivation` AS `gebruiker.cbactivation`, `gebruiker`.`banned` AS `gebruiker.banned`, `gebruiker`.`banneddate` AS `gebruiker.banneddate`, `gebruiker`.`unbanneddate` AS `gebruiker.unbanneddate`, `gebruiker`.`bannedby` AS `gebruiker.bannedby`, `gebruiker`.`unbannedby` AS `gebruiker.unbannedby`, `gebruiker`.`bannedreason` AS `gebruiker.bannedreason`, `gebruiker`.`acceptedterms` AS `gebruiker.acceptedterms`, `gebruiker`.`acceptedtermsconsent` AS `gebruiker.acceptedtermsconsent`, `gebruiker`.`cb_telefoon` AS `gebruiker.cb_telefoon`, `gebruiker`.`cb_adres` AS `gebruiker.cb_adres`, `gebruiker`.`cb_woonplaats` AS `gebruiker.cb_woonplaats`, `gebruiker`.`cb_postcode` AS `gebruiker.cb_postcode`, `gebruiker`.`cb_lidmaatschap` AS `gebruiker.cb_lidmaatschap`, `gebruiker`.`cb_knltbnummer` AS `gebruiker.cb_knltbnummer`, `gebruiker`.`cb_mobiel` AS `gebruiker.cb_mobiel`, `gebruiker`.`cb_sterkteenkel` AS `gebruiker.cb_sterkteenkel`, `gebruiker`.`cb_sterktedubbel` AS `gebruiker.cb_sterktedubbel`, `gebruiker`.`cb_functie` AS `gebruiker.cb_functie`
FROM `jos_comprofiler` AS `gebruiker`
WHERE `gebruiker`.`id` IN ('');
Notice that in the WHERE clause, after IN there's an empty value. Debugger says:
Impossible WHERE noticed after reading const tables
I also tried other combinations, same result.
there is a user logged in ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
also can you post a screenshot of your "where" setup ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
I test this form in the admin view, so I'm logged in as Admin.
Hans
your where value is set as {user.id} but it should be {user:id}
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
set your Read Data "select" to "First matching record", then change your field name to "Model.lastname", that's gebruiker.lastname and it should auto populate the field!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
When I use {gebruiker.lastname} it didn't work, but when I changed it to {var:gebruiker.lastname} it did.
Thanks for your help Max.
Regards, Hans
I'm saying changed the "Field name" (Veldnaam) to
gebruiker.lastname
But your solution is also fine, but it will just auto populate with my solution!
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
I misunderstood, but I tried and (of course :-)) this also works. Thanks again.
In another form, I've stored the result of an checkboxes-field in a db-field, type varchar. Result is: ["value 1", "value 2"]. How do I retrieve this from the db as default values of a checkboxes formfield? I guess I have to use the dynamic options feature, but can't figure out how that works.
the same way you are doing it now
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?