Joomla username syntax

MJudge 26 Jan, 2011
You had recently helped me with code for pulling joomla username to populate the name field on my form.
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 125px;">Member Username</label>
    <input class="cf_inputbox required" maxlength="80" size="15" title="Enter User Name!" id="text_1" name="text_1" type="text" value="<?php $user = &JFactory::getUser();echo $user->username;?>" />

Is it possible to remove the text entry option altogether for that unsername field - still displaying the username, but without the option of the user editing it?
Would you suggest code syntax change that would result in this?
Thanks again for your help.
Max_admin 26 Jan, 2011
yes, replace:
<input class="cf_inputbox required" maxlength="80" size="15" title="Enter User Name!" id="text_1" name="text_1" type="text" value="<?php $user = &JFactory::getUser();echo $user->username;?>" />


by
<?php $user = &JFactory::getUser();echo $user->username;?>
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
MJudge 27 Jan, 2011
OK I could give that a try, but won't there need to be some reference to the "text_1" field ID? How will the form update the username in the database and system email (for that entry) once the form is submitted?
Max_admin 27 Jan, 2011
Hmm, you want to update it ? but how ? I understood that you only need the username as a non editable text!!

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
MJudge 27 Jan, 2011
Yes I see the confusion. The goal is to have a working form with all the data transmitted as before, but without the text input feature of the username field. Although the text would not be editable by the user, how would that (non-editable) username information be transmitted to the database and form auto-email? Isn't there a continuing need to reference 'text_1' to allow the new form information to be updated in the database and transmitted with the other field information in the email. How else would we know which user is submitting that information?
MJudge 27 Jan, 2011
Sorry for the confusion. As I re-read the initial question I realize I wasn't clear. I continue to need the username (along with all the other form data) submitted with the form - added to the database and email info. The only difference should be that the user should not be able to edit or modify their name (thereby making results of a later data query much less usable).
MJudge 29 Jan, 2011
I think I have this thing pretty close to working, but there's a major flaw. Here is the original code that allows a user to edit their username:
<div class="form_item">
  <div class="form_element cf_textbox">
    <label class="cf_label" style="width: 125px;">Member Username</label>
    <input class="cf_inputbox required" maxlength="80" size="15" title="Enter User Name!" id="text_1" name="text_1" type="text" value="<?php $user = &JFactory::getUser();echo $user->username;?>" />


The following displays a nice bold version of the username on the form, but the data submitted by the form isn't quite right:
<div class="form_item">
  <div class="form_element cf_heading">
    <label class="cf_label" style="width: 125px;">Member Username</label>
    <h3 class="cf_text" id="text_1" name="text_1" value=>"<?php $user = &JFactory::getUser();echo $user->username;?>" 


What this modified code displays on the resulting email (and reports to the database) is "text_" (without the quotes) instead of the actual value of text_1 which of course should be the username itself. I'm just starting to learn html/css/php, but it seems like it might just be another minor tweak to get the proper result. Another thought I had is that I'm not sure if a form is even able to report anything other than text input (an input element)? Is what I'm trying to do possible?
Thanks in advance for your input
GreyHead 30 Jan, 2011
Hi MJudge,

Add the 'readonly' attribute to the input
<input class="cf_inputbox required" maxlength="80" size="15" title="Enter User Name!" id="text_1" name="text_1" type="text" value="<?php $user = &JFactory::getUser();echo $user->username;?>" readonly='readonly' />
This will display and return the data on submission without making it editable.

Bob
MJudge 30 Jan, 2011
That worked great. It behaved properly on the form and returned the form data as needed. Exactly what I was looking for!
GreyHead my man, you are AWESOME!
Thanks so much!
Admiral 11 Jun, 2011

Hi MJudge,

Add the 'readonly' attribute to the input

<input class="cf_inputbox required" maxlength="80" size="15" title="Enter User Name!" id="text_1" name="text_1" type="text" value="<?php $user = &JFactory::getUser();echo $user->username;?>" readonly='readonly' />
This will display and return the data on submission without making it editable.

Bob



GreyHead, the energy you spend on the board is above and beyond. Please know that you are truly appreciated!
With regard to the example in play, I have been able to adapt it to the Wizard so that the "custom changes" don't delete and still allow me to use the wizard. Two questions, first, in the wizard I have placed the php script in the "Field Default Value" of the wizard and it seems to work fine, do you see any issues placing it there?

Second the one piece of the code you wrote that I cannot seem to find a home for in the Wizard is the readonly='readonly' do you have any suggestions on how to get that into the wizard?

Thanks again
-Donald
GreyHead 12 Jun, 2011
Hi Donald,

You can't add an attribute in the Wizard (perhaps something that Max might add in a future release). That leaves you with a few choices:
[list=a]
  • Edit the Form HTML - but that means that you can no longer use the wizard

  • Use JavaScript to set the attribute when the page loads. Not so tidy but will work perfectly well.

  • Use a Custom Element to add this entry where you can add any HTML that you like.
  • [/list:o]
    Bob
    Admiral 13 Jun, 2011
    Thanks For the options, I went with the Custom element. Worked Great!

    Enjoy the Beer!

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