TOPIC:

Re:Populate Fields from Database Table 12 years 5 months ago #13341

  • nblit
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 16
  • Thanks: 0
Hi Erich,
What if i would like to use the user id instead of user email?

when i change the code to this nothing happens
$this->execPieceByName('ff_InitLib');
global $database, $record, $my;
$id = $my->id; //changed from email to id// 
echo $id; //this comes out empty//
$database->setQuery("
SELECT * 
FROM jos_comprofiler
WHERE id = '$id'"
);
$row = $database->loadObjectList();
$record = $row[0];
echo 

thanks

Please Log in or Create an account to join the conversation.

Last edit: Post by nblit.

Re:Populate Fields from Database Table 12 years 5 months ago #13342

  • erichhaubrich's Avatar Topic Author
  • erichhaubrich
  • Offline
  • Junior Breezer
  • Junior Breezer
  • Web Ninja and Technology Geek
  • Posts: 53
  • Karma: 4
  • Thanks: 3
You have to use the echo command to call the string into the value, not in the form piece. You run the query in the form piece then call the result into the Value.

Something like this in the Value:
<?php global $record; return $record->whatever_field; ?>

If you're just trying to pull in their basic user information into a form element then you should be able to just use this:

User ID:
<?php $user = &JFactory::getUser();return $user->id;?>
Name:
<?php $user = &JFactory::getUser();return $user->name;?>

Email:
<?php $user = &JFactory::getUser();return $user->email;?>

I hope this helps.
I love Breezing Forms! - It is the Killer App for Forms on Joomla!

Please Log in or Create an account to join the conversation.

Re:Populate Fields from Database Table 12 years 4 months ago #13345

  • nblit
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 16
  • Thanks: 0
Hi Erich,

Thanks for the prompt reply,
I have placed the echo in the code in order to see what is populated, unfortunately there is no data in $ID.

What i am trying to do is query the jos_comprofiler table based on the user ID, not the email address, this table does not contain the users email address, but there is other data that i want to pull into the form.

So if you can modify the following, to show me how it can do it i would be very grateful
// Get the lead info fo the current user
$this->execPieceByName('ff_InitLib');
global $database, $record, $my;
$id = $my->email; 
$database->setQuery("
SELECT * 
FROM jos_comprofiler
WHERE email = '$id'"
);
$row = $database->loadObjectList();
$record = $row[0];

thanks for your time,
NB

Please Log in or Create an account to join the conversation.

Last edit: Post by nblit.

Re:Populate Fields from Database Table 12 years 1 month ago #16238

  • jurgen0
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 5
  • Thanks: 0
I've tried this but it didn't work. So I've made a few small modifications:

PART 1

Go to your form's proporties, then the "Advanced" tab > "More options". In the popup select the tab "Form pieces". In the "Before form" section, choose "Custom". Paste the next script there and save.
$this->execPieceByName('ff_InitLib');
$user = &JFactory::getUser();
global $database, $record;
$id = $user->email;
$database->setQuery("SELECT * FROM #__[TABLE_NAME] WHERE [EMAIL_FIELDNAME] = '$id'");
$row = $database->loadObjectList();
$record = $row[0];

1 Change [TABLE_NAME] to the name of the table you wish to get the data from (without the prefix). For example: 'qcontacts_details' (without quotes). QContacts is a contactmanagement component ( Qcontacts ). Don't worry about the prefix, in most cases 'jos_' (without quotes). The '#__' (without quotes) takes care of that. With this the prefix doesn't matter anymore.
2 Change [EMAIL_FIELDNAME] to the name of the field that contains the emailaddress in the table you wish to get the data from. For example: 'email_to' (without quotes) at the QContacts example.

If you don't want to use the emailaddress to retrieve the data with, but, for example, the ID, modify the line
$id = $user->email;
to
$id = $user->id;
and
$database->setQuery("SELECT * FROM #__[TABLE_NAME] WHERE [EMAIL_FIELDNAME] = '$id'");
to
$database->setQuery("SELECT * FROM #__[TABLE_NAME] WHERE [ID_FIELDNAME] = '$id'");

[ID_FIELDNAME] is the name of the ID field in the table you wish to get the data from.

PART 2

Fill in the next codes to your form 'Value' fields (pick the ones you need):

Name field:
<?php $user = &JFactory::getUser();return $user->name;?>

Email field:
<?php $user = &JFactory::getUser();return $user->email;?>

Other fields:
<?php global $record; return $record->[FIELD_NAME]; ?>

[FIELD_NAME] is the name of the field in the table you wish to get the data from. For exeample: 'telephone' (without quotes) at the QContacts example.


I hope this is of any help for you people.

Please Log in or Create an account to join the conversation.

Re:Populate Fields from Database Table 12 years 1 month ago #16361

  • havoc
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 3
  • Thanks: 0
Here's my initial take:

In PHP, whenever you use single quotes, you actually say "use this string as a literal string." Thus, in the portion WHERE u.email = '$id', you are actually plugging-in the literal string "$id" (not the value that $id contains) in your query statement.

I suggest you break this portion up to be something like:
$database->setQuery("
SELECT a.userid as `UserID`, 
...
WHERE u.email = " . $id . 
" GROUP BY a.userid
ORDER BY u.name, a.userid"
);

HTH!

Please Log in or Create an account to join the conversation.

Last edit: Post by havoc. Reason: typo in code

Re:Populate Fields from Database Table 11 years 10 months ago #21530

  • jttechnet
  • Offline
  • Fresh Breezer
  • Fresh Breezer
  • Posts: 1
  • Thanks: 0
Using Easy Mode, I tried this method but Joomla is not pharsing the code inside the fields and just outputs it as if it were normal text. I did a print_r in the Before Form and saw the result I was expecting so I know that part is processing right.

Any thoughts? Is this a Joomla or BF issue ?

Joomla Version: 1.5.20 Stable [ senu takaa ]
BF Version: 1.7.2 Stable (build 737) [Trinity]

Please Log in or Create an account to join the conversation.

Moderators: ForumSupport
Time to create page: 0.052 seconds

BreezingForms Pro 1.4.7 for WordPress Released!

Available in the membership section.

September Discount!

Massive discounts on all subscriptions!

Get Your Subscription Here

Quick Links

Downloads

BreezingForms

ContentBuilder

BreezingCommerce

Templates

Documentation

BreezingForms

ContentBuilder

BreezingCommerce

Apprendre BreezingForms (French Community)

Apprendre et maîtriser BreezingForms par des tutoriels et exemples, le tout en français

breezingforms.eddy-vh.com

Questions et réponses sur les forums de l'AFUJ

AFUJ

Special Offer

Summer Sale! All subscriptions at a special price!

Includes prio support, all of our current and future Joomla!® extensions and Joomla!® templates for the duration of your membership.

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!