Forums

How do I pull in the logged in users username into a form

mlklocke 18 Mar, 2012
We are setting up an order entry form for a client and they want the forms to auto-populate with the logged in users name from the joomla user information. What kind of code would i use and where would it go? I also want this information to upload into the database where the order information is being stored.
mlklocke 18 Mar, 2012
just as a follow up question the field that i want this information to post to the associated table is called "aff_id"

The code i am using for this form is a custom form so i would need to be able to modify the custom code
GreyHead 18 Mar, 2012
Hi mlklocke,

The code is here in the forums dozens of times . . .

You can use my custom Load User Info action but that is probably more that you need here.

You can add a Custom action into the On Load event and put this code into it:
<?php
$user =& JFactory::getUser();
$form->data['username'] = $user->username;
?>

Then you can add an input with the name username or include {username} in the HTML of a Custom element.

If you create the table with ChronoForms or add a cf_user_id column to an existing table the the Db Save action will automatically save the current User ID (not the username). The ID is more useful as, unlike the username, it doesn't ever change and you can use it to look up the username whenever you need it.

Bob
mlklocke 18 Mar, 2012
okay yes after the fact i found the information to get the username and that works for me however i dont know how to get it into the form since its a custom form and not using the wizard😟 sorry for sounding dumb i just have never done this before
GreyHead 18 Mar, 2012
Hi mlklocke,

. . . you can add an input with the name username or include {username} in the HTML . . .

Bob
mlklocke 31 Mar, 2012
Okay i am still struggling with this. if you look at the screenshot attached i am trying to pull in the user name of the logged in user and assign it to form data as aff_id, when i view the form from the front end view all i see is the field lable and no data so there is no way to test or at lease i cant tell if the data is in the aff_id field. I am NOT a programmer so please explain what i am doing wrong😟 I have tried putting in a line with echo aff_id; but then all that shows up is the label name and aff_id in text not the value of that field.
mlklocke 31 Mar, 2012
I got this figured out now! Thanks
This topic is locked and no more replies can be posted.