ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

How to read a db value into a form field?

hpeterse 04 Dec, 2020
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?
Max_admin 05 Dec, 2020
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 ?
hpeterse 05 Dec, 2020
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
Max_admin 05 Dec, 2020
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 ?
hpeterse 05 Dec, 2020
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.
Max_admin 08 Dec, 2020
there is a user logged in ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
Max_admin 08 Dec, 2020
also can you post a screenshot of your "where" setup ?
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
hpeterse 10 Dec, 2020
I test this form in the admin view, so I'm logged in as Admin.

Hans
Max_admin 12 Dec, 2020
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 ?
hpeterse 12 Dec, 2020
Thx Max, I should read better. Now it works.
Now I'm trying to use the db-values as default value for the form fields. I my formfield I've added an advanced setting 'value & placeholder' and as value I've added:
{data:gebruiker.lastname} (where gebruiker.lastname is retrieved based on the query).

However, the result is an empty field. Should I also use "data" in the brackets, of should I use another function here? And if so, why is it still empty?
Default_db_value.png
Max_admin 14 Dec, 2020
Answer
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 ?
hpeterse 14 Dec, 2020
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
Max_admin 14 Dec, 2020
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 ?
hpeterse 14 Dec, 2020
I misunderstood, but I tried and (of course :-)) this also works. Thanks again.
hpeterse 15 Dec, 2020
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.
Max_admin 22 Dec, 2020
1 Likes
the same way you are doing it now
Max
ChronoForms developer...
Did you try ChronoMyAdmin for managing your Joomla database tables ?
You need to login to be able to post a reply.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com