Buy Now
Sign in

Save user-name to a table?

kizo , October 29 2007, 16:10
K
kizo 9
October 29 2007, 16:10 #3173
Hi.
I'm currently using:

<?php
$user = &JFactory::getUser();
if(!$user->id){return;}
?>


to restrict a form to registered and logged in users only.

I'm wondering if there is any way to save the username of that user in a table, without having them entering it?

How do I "get" the username, and how do I create that table. Should I do it in phpMyAdmin?

Thanks in advance!
admin 27
October 29 2007, 20:16 #3181
Hi Kizo,

You can make a hidden field at your html called "username", then you create a table for your form, check the username box, now you have a column called username, at the HTML of your form, add this code in the value attribute of your username field :



<?php
$user = &JFactory::getUser();
echo $user->username;
?>
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
K
kizo 9
October 29 2007, 20:40 #3186
admin wrote:
You can make a hidden field at your html called "username"

How do you suggest I hide it?

Thank you.
admin 27
October 29 2007, 20:41 #3187
its already hidden, its a "hidden" field, something like this :

<input type="hidden" name="username">


;)
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!
K
kizo 9
October 29 2007, 22:08 #3191
Works great!
Once again, admin has saved the day.

Thank you!
admin 27
October 30 2007, 01:03 #3196
Thanks Kizo!
Max
If your main question got answered then please mark the answer using the button!
Please let us know if you have any problems with the new forums text editor, we appreciate your feedback!