Page 1 of 1

Customising a component: call a username

Posted: Wed Feb 13, 2008 11:08 pm
by andrewvanmarle
I'm working with Linx a links submission component, which is great but I'd like to modify it slightly:

where it asks you to enter your name in a field, i'd like it to hard code the users (user)name:

This is from the php file and creates the fields to fill stuff in:

$recip_url = mosGetParam( $_REQUEST, 'recip_url', '' );
$new_url = mosGetParam( $_REQUEST, 'new_url', '' );
$new_url_name = mosGetParam( $_REQUEST, 'new_url_name', '' );
$new_url_description = mosGetParam( $_REQUEST, 'new_url_description', '' );
$new_name = mosGetParam( $_REQUEST, 'new_name', '' );
$new_email = mosGetParam( $_REQUEST, 'new_email', '' );
$cat_id = mosGetParam( $_REQUEST, 'cat_id', '' );

I'd like to replace this:
$new_name = mosGetParam( $_REQUEST, 'new_name', '' );
with something that calls the (user)name instead of the field.

I grabbed this from the debug when opening a (community builder) profile page:
7
SELECT id, name, email, block, sendEmail, registerDate, lastvisitDate, activation, params
FROM jos_users
WHERE id = 62

I tried echo statements, but all i got was errors, what should I do?

Re: Customising a component: call a username

Posted: Sat Feb 23, 2008 10:37 pm
by macbloke
In J!1.0 you need to use:

Code: Select all

global $my;

$userid = $my->id;
$username = $my->username;

In J!1.5 you need to use:

Code: Select all

$user =& JFactory::getUser();

$userid = $user->get('id');
$username = $user->get('username');

Hope this helps.

StuG

Re: Customising a component: call a username

Posted: Sun Feb 24, 2008 7:03 pm
by andrewvanmarle
Hey stu, thanks for the first step ...

I tried copying that in the php doc...and got an error:

Code: Select all

Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in D:\Website\xampp\htdocs\nedgolfvet\components\com_linx\linx.php on line 203
Guess I should have done something different?

(maybe a touch of back ground will help:
The is the linx component, and hat I want to happen is that instead of a user being asked to fill in a name, it's automatically filled in for him so there is no chance of "fudging")

Re: Customising a component: call a username

Posted: Sun Feb 24, 2008 7:25 pm
by macbloke
You're missing a ';' from the end of one of the lines. Check you've got them all complete and you should be good to go.

Regards,

StuG

Re: Customising a component: call a username

Posted: Sun Feb 24, 2008 7:28 pm
by macbloke
If you're copying directly, you might want to use:

Code: Select all

$new_name = $username;
in lieu of your mosGetParam request.

StuG

Re: Customising a component: call a username

Posted: Sun Feb 24, 2008 11:08 pm
by andrewvanmarle
thanks i'll try it at once!