Login
Please enter your email address and password to login to the help desk.
(leave blank if you forgot your password)
   Save my login information
 

IMPORTANT NOTE:

DUE TO STUCTURAL CHANGES, THE TICKET SYSTEM IS NO LONGER ACCEPTING TICKETS. IF YOU ARE A PAYING SUBSCRIBER, PLEASE LOGIN TO THE CROSSTEC SITE AND USE THE CLUB FORUMS. THE CLUB FORUMS CATEGORY WILL APPEAR RIGHT AFTER LOGIN IF YOU ARE A PAYING CUSTOMER:

>>> Click here to access the forums <<<

We will close the knowledgebase soon as well and move its contents into a new knowledgebase system.

Knowledge Base » BreezingForms » FAQ
Populate Fields from Database Table
Is there a way to populate fields from a database table?

(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