Forums

Add current user id in the email template?

hejabajen 11 Nov, 2009
Hi! This is my first visit here at this gr8 forum, so hello! (and be gentle).

I did a search on my query but didnt find anything, i hope it is safe to post.

What i need is to add the current user id to the Email template, is it possible?
(so that i can see who has actually filled out the form, should there be more than one John Doe users registered)

Tnx to the Chronoforms crew and all users keeping this community alive.

/Hejabajen
GreyHead 11 Nov, 2009
Hi Hejabajen,

The simple way is to add a hidden field to your Form HTML with the user-id in it, then that will be added to the template.
<?php
$user =& JFactory::getUser();
?>
<input type='hidden' name='user_id' value='<?php echo $user->id; ?>' />

If you are manually editing your template then add {user_id} to show the value.

Bob

PS You could add similar PHP to the email template but you need to turn off the HTML editor to do that so this way is a little easier.
hejabajen 11 Nov, 2009
Thanks for the quick reply Bob.

I think i did just what you wrote, (probably not). However, i get the following error after pushing the submit button:

../"public_html/libraries/joomla/database/database/mysql.php on line 540"

Under the form code tab i added the code you gave me right at the top:
"<?php
$user =& JFactory::getUser();
?>
<input type='hidden' name='user_id' value='<?php echo $user->id; ?>' />

<div class="cf_item"> <h3 class="cf_text">Your Contact Information:</h3> </div>

<div class="cf_item">
<h3 class="cf_title" style="width: 150px;">Full Name:</h3>
<div class="cf_fields">
<input name="text_27" type="text" value="" title="" class="cf_inputtext cf_inputbox" maxlength="150" size="30" id="text_27" />
<br />
<label class="cf_botLabel"></label>
</div>
</div>"


And then added the user_id to the template:
"User Id:
{user_id}

Contact Information:
Full Name:
{text_27}"


I guess i did something wrong?
lundmark 21 Nov, 2009
I was looking for something similar to this, but with a sequential number, for an order reference. I tried {cf_id} in the email template but no luck.

I tried this option and it works great. Any way to modify it to number in sequence or use the cf_id already being used, or a simple solution?

Thanks, love the product.
GreyHead 21 Nov, 2009
Hi hejabajen and lundmark.

@hejabajen: the error message you posted is incomplete. Hard to tell what is happening without the rest of the message. I don't think this is caused by the other code though - that looks OK.

@lundmark: cf_id is only reliably available after the data is saved. So you have to change the run order of the ChronoForms actions. There are several threads around discussing using cf_id, please see if you can find the answer in a recent one, if not ask again.

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