(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
global $database, $record, $my;
$id = $my->email;
WHERE email = '$id'"
$row = $database->loadObjectList();
$record = $row;
<?php $user = &JFactory::getUser();return $user->name;?>
<?php $user = &JFactory::getUser();return $user->email;?>
<?php global $record; return $record->hphone; ?>
<?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|