Forums

How to insert username along with form submission?

sinivasan 17 May, 2015
Hello,

I have created a simple form with 6 fields. works nicely.

I want to save the current logged in user's name into database along with forms values when user submits the form, how to achieve this?

(I'm not coder, still I can understand little bit of codes)

Thanks in advance.
GreyHead 17 May, 2015
Hi sinivasan,

If there is a user_id column in the table then the User ID will be saved that may be enough as you can always look up the username from the ID, even if the username changes.

If you need the username, please see this FAQ

Bob
sinivasan 17 May, 2015
Answer
Thanks GreyHead,

I made it using custom action and hidden field

custom action
<?php
$user = JFactory::getUser();
$form->data['user_name'] = $user->username;
?>
user_name is hidden field.

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