Show username on form

supertux 04 May, 2011
Hi,

i want to show the username of the currently logged in user on the form.

I tried the following:

Drag and Drop a Custom Element in the Wizard

On the "Code" Property I inserted:

<?php

$user =& JFactory::getUser();
echo "<p>Your username is {$user->username}</p>";

?>


But on the Frontpage View, I only get "Your username is ", the username doesn't show up ๐Ÿ˜ข

Any suggestions on how to show the username?

Thanks!
GreyHead 04 May, 2011
Hi supertux,

The code looks correct to me - it will only display the username if you are logged in though.

Bob
supertux 04 May, 2011
I'm unbelievable stupid, I was logged in at the backend, but not in the frontend, so it's no wonder it didn't show the username. ๐Ÿ™„

Thank you anyways!
supertux 04 May, 2011
There's still one problem:

I create a textbox, as default value i chose "<? echo "welcome ". $user->username; ?>"

Then I click Apply, Close, and Save the form.

When I go to preview, all works fine.

But then, when I click "Wizard Edit" again, the textbox gets totally messed.

Show username on form image 1

If I click Save and then go to Preview, I get an Error message.

๐Ÿคจ
GreyHead 04 May, 2011
Hi supertux,

I don't think that you can put PHP into a default value box. I believe that you can only use text strings there.

Bob
supertux 04 May, 2011
Well it works, as long as you save your form for the first time. As soon as you reopen the form to make some changes, it gets corrupted.

So I think the better solution ist to use the "Custom Element".
This topic is locked and no more replies can be posted.