Forums

textbox filled with username

giacall 16 May, 2014
Hi to all experts..
First of all... sorry for my english...

I need a little help...
I've a form with some field.. I would like to fill a "read-only" textbox (disabled textbox) with the value 'id-name' of a logged user.

so.. i know that i can do


<?php
$user =&JFactory::getUser();
$id = $user->id;
$nome = $user->name;
?>

but.. how i can put this value in the disabled textbox value??

Thank's in advance
GreyHead 16 May, 2014
Hi giacall,

Please see this FAQ it talks about the On Submit event but will work equally well in the On Load event.

Bob
giacall 09 Jun, 2014
Hi GreyHead.

Thank for replay..

I read the faq you suggest to me.. Bu t i think is for CV4. I'm using CF5....
BTW..

I can use the $user array through the code

<?php
$user =& JFactory::getuser();
?>


Then i've my information in
$user->name 


What i cannot do is "write" the $user->name in the value option of a textbox...

The FAQ refer to DB Record Loader Action.. wich is not present in CF5 (i think the corrispective is DB READER)
Thank's in advance
GreyHead 09 Jun, 2014
Answer
1 Likes
Hi giacall,

You are right that the FAQ was written for CFv4 and the code should still work for CFv5. Have you tried it?

Bpb
giacall 09 Jun, 2014
OOOOkkkkkkkk... Ok ok...

So... I tryed with the example in FAQ you suggest me previously, mixed with FAQ How to load record data from a database table into your form and How can I edit a record from a database table?

Finally, with CF5 and DB Reader, i can load the id and email from users table.. Set 2 textbox id with "id" and "email" and setting a DBReader event in ONLOAD section (above HTML RENDER FORM) with


<?php
return array("id" => form->data("id"));
return array("email" => form->data("email");

?>


in condition field, i can have the ID and EMAIL of a unic user registered in joomla.

But.. If i would to have the id and email of a currently logged in user, i suppose i've to use the custom code action in onload section..

I tryed with this code in CUSTOM CODE ACTION:

<?php

$user =& JFactory::getUser();
$id = $user->id;
$email = $user->email;
return array($id => $form->data("id"));
return array("$email" => $form->data("email"));

?>


And.. of course ... it does not work..

Can you xplain me hoe to use the form data array, and how to have the current logged in user ID and email in 2 separated text box??

Thank's in advance
giacall 09 Jun, 2014
OPS...

Hello GreyHead..

The form works fine.. Was my mistake on PHP code (and on my very basic know about array....)

The right code in CUSTOM CODE action is :

<?php

$user =& JFactory::getUser();
$id = $user->id;
$email = $user->email;

$form->data['id'] = $id;
$form->data['email'] = $email;
?>


Thank's for your help!!!
GreyHead 09 Jun, 2014
Hi giacall,

You seem to be making this very complicated :-(

What are the names of the text-boxes that you want to use to show the name and id?

Bob
giacall 09 Jun, 2014

You seem to be making this very complicated :-(


You are right.. But as i wrote in my last post.. Was my mistake in PHP code.

Now works fine..

Thank's
GreyHead 09 Jun, 2014
1 Likes
HI giacall,

Ah sorry, I didn't see your last post before writing mine :-(

You can simplify even more to this
<?php
$user =& JFactory::getUser();
$form->data['id'] = $user->id;
$form->data['email'] = $user->email;
?>

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