Forums

pre-populate a form field with user data

flaco 08 Apr, 2016
hello to all the forum users
I made a custom form for user registration
I have two tables for data logging
"os_user" (joomla standard)
"tabella_registrazione" that contains the phone name and other fields ...
everything works perfectly.
I made a form for booking events and I would like the fields name, surname, email and phone are precompiling.
I entered the fields of jos_user table but I can not for the tabella_registrazione table using DB_READ
like in the pictures
can you give me some help? thank you
-------------------------

--------------------------

---------------------------
GreyHead 09 Apr, 2016
Hi fiaco,

You need an entry in the Conditions box to identify the record that you want to read. It will be something like this
<?php
$juser = \JFactory::getUser();
return array( 'user_id' => $juser->id );
?>
I don't think that you need the Join Condition here.

Bob
flaco 09 Apr, 2016
Thanks !!
great! I'll try !
I was sure it needed a script to point to the ID of the table
Now I am out for weekend , but tomorrow night I will be at the computer ;-)
sorry for my "google" English :-)
flaco 11 Apr, 2016
Hi GreyHead

I tried a lot but it does not work.
to read data from the table I found a solution by placing a field (user) in the hidden form that is filled with "id" of the table jos_user

then I found this statement in the faq and I inserted it in the conditions of the READ DB (base) that reading the "user" field of the form builds a WHERE condition

<? Php return array ( "user_id" => $ form-> data ( "user")); ?>


Now DB_READ point the table "tabella_registrazione" from which I have to take "cognome" and "telefono"

here is debugging
-----------------------
Array
(
[option] => com_chronoforms5
[chronoform] => prenotazione40
[nome40] => capuzzi
[email40] => sneering@virgilio.it
[user] => 69
[data00] => Array
(
[user_id] => 69
[cognome] => tiziana
[telefono] => 222222
)

[telefono40] =>
[cognome40] =>
)
--------------------------
I tried to put in the clause "on_found" a "custom code" to write "cognome" and "telefono" in their respective fields in the form "cognome40" and "telefono40", but I can not find the syntax to use and they appear empty (red in debugging)
I activated model_id called "data00" and I put in custom code :

<?php
$form->data['telefono40'] = $data00->telefono;
$form->data['cognome40'] = $data00->cognome;
?>

but d'ont work :?

do you have any solution?lightbulb
thank you so much
GreyHead 12 Apr, 2016
Hi flaco,

It looks as if you have the data but in an array, not an object so your code would need to be:
$form->data['xxx'] = $data00['zzz'];


Bob
flaco 13 Apr, 2016
Hi GreyHead

Hi fiaco,

You need an entry in the Conditions box to identify the record that you want to read. It will be something like this

<?php
$juser = \JFactory:;getUser();
return array('user_id' => $juser->id;
?>
I don't think that you need the Join Condition here.
Bob



Your suggestions were right, I wrong putting them in place.
In particular it was necessary that the form fields have the same name of the table fields (cognome and telefono) and everything went perfectly.
Thank you very much !!
This topic is locked and no more replies can be posted.