Forums

Get user ID

proso 01 Feb, 2013
Hello,

I'm trying to add a email function to reply to the user who submitted it.

The email, with a custom code before works with this code:

<?php
$user =& JFactory::getUser(79);
$form->data['user_email'] = $user->email;
?>

But now I want the number 79 to be dynamic by using cf_user_id. I tried to load this by using DB Record Loader with request parameter as 'gebruiker'. This works because the tag {gebruiker} will give the id 79 when I add this tag to the email template.

But when I add gebruiker (or 'gebuiker' or $gebruiker) to the code, it won't work:

<?php
$user =& JFactory::getUser(gebruiker);
$form->data['user_email'] = $user->email;
?>


I really don't know how to do this the right way. I hope one of you can help me?

Thanks,

Erwin
proso 04 Feb, 2013
Is there someone who knows the answer? I'ts probably something small. I'm really stuck 😟
Max_admin 07 Feb, 2013
Hi proso,

You want to get the logged in user's email address ? please try:

<?php
$user = JFactory::getUser();
$form->data['user_email'] = $user->get('email');
?>


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
proso 07 Feb, 2013
Hi Max,

I'm looking for the user who submitted the form. I'm trying to get the authors ID from cf_user_id and their email from the Joomla registration. Is it something like this?
<?php
$user = $form->data['cf_user_id'];
$form->data['user_email'] = $user->email;
?>
GreyHead 07 Feb, 2013
Hi proso,

Is this the user who has **just** submitted the form?? In that case please use Max's code.

If it is the user who submitted the form some time in the past and you are looking up the record in a DB Table then you may need something different.

Bob
proso 08 Feb, 2013
Hi GreyHead,

It is the second option. My users can login on the website and submit articles whenever they want. As an admin, i want to reply to the different authors. In the cf_user_id I can find the authors ID, and the email is in the joomla user database. What method do I need for this? Thanks
GreyHead 08 Feb, 2013
Hi proso,

<?php
$user_id = $form->data['cf_user_id'];
$user = JFactory::getUser($user_id);
$form->data['user_email'] = $user->email;
?>

Bob
proso 08 Feb, 2013
Hi, I tried the code, but the email is sending to my own admin email, in stead of sending it to the article author. Maybe I'm doing something else wrong?
I added the custom code before the email action (in On submit). I also added a bugtracker:

Array
(
[token] => 5414078a8872bbec2952a70c548ca899
[gebruiker] => 79
[chronoform] => overzicht_artikelen_detail
[event] => submit
[Itemid] => 338
[option] => com_chronoforms
[view] => form
[onderwerp] => De opkomst van de weerwolf
[tekst] => sdf asdfasdfgsdfg
[omschrijving] => dsfg sdfgd sfg
[zoekwoorden] => dsfgdfg,sdf ,dfg ,dsfg
[bron1] => <!-- w --><a class="postlink" href="http://www.wilikweten.nl">www.wilikweten.nl</a><!-- w -->
[bron2] => <!-- w --><a class="postlink" href="http://www.wilikweten.nl">www.wilikweten.nl</a><!-- w -->
[bron3] => <!-- w --><a class="postlink" href="http://www.wilikweten.nl">www.wilikweten.nl</a><!-- w -->
[bron4] => <!-- w --><a class="postlink" href="http://www.wilikweten.nl">www.wilikweten.nl</a><!-- w -->
[bron5] => <!-- w --><a class="postlink" href="http://www.wilikweten.nl">www.wilikweten.nl</a><!-- w -->
[opmerkingen] =>
[status] => In behandeling
[email_versturen] => E-mail versturen
[categorie] => No
[afbeeldingen_aanw] =>
[volledig_artikel] =>
[cf_id] => 1
[ca1c3a7b39372027e48cacd96ee9142f] => 1
[user_email] => [email]info@wilikweten.nl[/email]
)
Validation Errors:
Array
(
)
GreyHead 08 Feb, 2013
Hi proso,

I don't see any value for cf_user_id in the debug data.

Bob
proso 10 Feb, 2013
Hi Greyhead,

The cf_user_id is called 'gebruiker' in the form, which is 79 (and works). The strange thing is that when I use the code you gave me or this code:

<?php
$user =& JFactory::getUser($gebruiker);
$form->data['user_email'] = $user->email;
?>


it is giving me user_email => info@wilik... (which is the admin email, ID 42) instead of test@wilik... (ID 79)

But when I use the next code, it is working fine: user_email => test@wilik...
<?php
$user =& JFactory::getUser(79);
$form->data['user_email'] = $user->email;
?>


Maybe it is something with my form?
GreyHead 10 Feb, 2013
Hi proso,

If you are getting the Admin info - is this when you are logged in as Admin? Then I'd guess that $gebruiker is empty so the data is being returned for the currently logged in user.

Bob
proso 11 Feb, 2013
Yes I'm logged as admin. I think you're right, although it does works in a custom code, using {gebruiker}.
Do you have an idea how to fix this?
Thanks
GreyHead 11 Feb, 2013
Ho proso,

OK. Then please try using $form->data['gebruiker'] in the PHP.
<?php
$user =& JFactory::getUser($form->data['gebruiker']);
$form->data['user_email'] = $user->email;
?>

Bob
proso 12 Feb, 2013
Works liek a charm! Thank you very much, you made my day!
This topic is locked and no more replies can be posted.