Capture User Name and Email

jlcarpenter 17 Jun, 2013
I am creating a form and would like to capture the user name and email. I thought I had the code but when I try to echo it to the screen both variables are blank. Below is the code. I am still trying to figure out both ChronoForms and PHP so it could be either one where I have a problem.

<?php
$user = &JFactory::getUser();
$useremail = $user->email;
$username = $user->name;

echo "user email is $useremail \r\n";
echo "user name is $username \r\n";

?>


Thanks,
James
GreyHead 17 Jun, 2013
Hi James,

The code looks OK to me. Where are you putting it?

Please see this FAQ

Bob
jlcarpenter 17 Jun, 2013
Ok. Major mess up on my part. My user id had timed out so when I went to view it from the forms manager I was not logged in. When I log in, everything seems to work good. I am wanting to grab the name and put it in an email.
jlcarpenter 17 Jun, 2013
One more question. I am trying to put the user name in an email so I have the code shown above and add the following line
JRequest::setVar('user_name',$user->name);
.

In the email template section, I add "{user_name} just completed the Survey". When I receive the email, all I see is "just completed the Survey", but I see the user->name echoed out from the previous code.
GreyHead 17 Jun, 2013
Hi jlcarpenter,

Please check the FAQ I linked to in my earlier post. The code you have in your last post was good for CFv3 but will not work the same way in CFv4.

Bob
This topic is locked and no more replies can be posted.