(Contributed by Erich Haubrich)
I looked around for a way to populate fields in a form from the database
if a user is logged in. I hacked together a few pieces of code and came
up with this. IT WORKS! - Note: I am using it in Quick Mode.
In this case, the table that I'm pulling from has the user's email
address in it - this grabs the email address of the current user and
finds that email in the table I am querying, then populates the field
values of the form.
I am using it to populate the mobile phone and home phone of the user in
a contact form.
Before Form Piece
// Get the lead info fo the current user
$this->execPieceByName('ff_InitLib');
global $database, $record, $my;
$id = $my->email;
$database->setQuery("
SELECT *
FROM jos_[your_table_name]
WHERE email = '$id'"
);
$row = $database->loadObjectList();
$record = $row[0];
FORM VALUES:
Name:
<?php $user = &JFactory::getUser();return $user->name;?>
Email:
<?php $user = &JFactory::getUser();return $user->email;?>
Home Phone:
<?php global $record; return $record->hphone; ?>
Mobile Phone:
<?php global $record; return $record->mobile; ?>
If you just want to populate the name and email then you can skip the
Before Form Piece and just use the values for Name and Email.
![]() |
Was this helpful?
Yes
No
Print
Pdf
|

