capture user name in text field read only

guillegm 29 Feb, 2012
Hi,
I need to capture the username and put it into a text field read only. In chronoforms V3 I know how to do this by editing the source code, but in V4 I don't.😢
I only have achieved to get the username placing a "custom code" action before "show html". The "custom code" is
<?php
$user =& JFactory::getUser();
echo $user->username;
?>

Now I need to put it into a text field. I tried to put <?php echo $user->username; ?> on text field value, but don't work.
Thanks a lot. 😀
GreyHead 29 Feb, 2012
Hi guillegm,

Please use this in the Custom Code action
<?php
$user =& JFactory::getUser();
$form->data['username'] = $user->username;
?>

Bob
guillegm 01 Mar, 2012
Thanks bob, it works. How can I do readonly textfield?
GreyHead 02 Mar, 2012
Hi guillegm ,

Three ways: [list=a]
  • Use a Custom element and put {username} in it; you also need a hidden input if you want to have the value in the form results.

  • Edit the Form HTML on the Form code tab and put readonly='readonly' in the input tag

  • Use a JavaScript snippet to set readonly after the page loads

  • later: Use a Custom element and put {username} in it (see gabedaly's post below)
  • [/list:o]

    Bob
    gabedaly 04 Mar, 2012
    I have also used the Header element in conjunction with DB Record Loader to display a read only field like this:
    Your username is {username}
    It works good and it helps me to see it on the form preview in the backend.
    This topic is locked and no more replies can be posted.