Author Topic: Remove Displayed Name / username field  (Read 24474 times)

littlesnack

  • Beginner
  • *
  • Posts: 11
Remove Displayed Name / username field
« on: September 04, 2012, 17:39:13 pm »
I made this tweak to remove the displayed name (COM_VIRTUEMART_USER_DISPLAYED_NAME) and the username field.
There should be an option to use email as username, and simply save mail as user in joomla too.

Anyway, copy components\com_virtuemart\views\user\tmpl\edit_address_userfields.php inside /templates/[yourtemplate]/html/com_virtuemart/user/ (create folders if they don't exist) , add the code below and it'll work.
Download the attachment to get the complete file for virtuemart 2.0.10

Code: [Select]
        echo ' <table  class="adminForm user-details">' . "\n";
$_table = true;
    }
    echo ' <tr>' . "\n";
    echo ' <td class="key" title="'.$_field['description'].'" >' . "\n";
    echo ' <label class="' . $_field['name'] . '" for="' . $_field['name'] . '_field">' . "\n";
    echo ' ' . $_field['title'] . ($_field['required'] ? ' *' : '') . "\n";



and replace
Code: [Select]
echo ' <tr>' . "\n";with
Code: [Select]
if($_field['name'] == "name" or $_field['name'] == "username"){
echo ' <tr style="display:none;">' . "\n";
}
else{
echo ' <tr>' . "\n";
}
What does it do: makes the tables row for the field user and username invisible

Then add this in the bottom of the script
Code: [Select]

?>
 <script type="text/javascript">
 if (document.getElementById('email_field')) {
  document.getElementById("email_field").setAttribute("onchange", "utente_uguale_email()");
 }
 
    function mail_is_user(){
var reg_email = document.getElementById("email_field").value
document.getElementById("name_field").value = (reg_email);
document.getElementById("username_field").value = (reg_email);
}

 </script>
 
 <?php
What does it do: adds a javascript function. When the user writes something in the email field, we'll copy that inside our invisible user and username fields


[attachment cleanup by admin]

ivus

  • Full Member
  • ***
  • Posts: 534
  • - YAY me... proud member of the 500 club...
Re: Remove Displayed Name / username field
« Reply #1 on: September 05, 2012, 00:59:53 am »
@littlesnack,

Quote
Warning: always back up your file before editing it

NOTICE: You should never hack the core template (or the core files in general). Use template overrides, that's what they're there for.

http://docs.joomla.org/How_to_override_the_output_from_the_Joomla!_core
http://docs.joomla.org/Understanding_Output_Overrides

But otherwise, a nice solution.

DaggaTora

  • Full Member
  • ***
  • Posts: 253
Re: Remove Displayed Name / username field
« Reply #2 on: September 05, 2012, 09:14:26 am »
Mmmm... very very interesting....

Thx snack!!



Quote
Warning: always back up your file before editing it

[

After a year tunning everything... ;D I have 2 pages list of hackings for every update!
Joomla 2.5.17 | VM2.0.26d | PHP 5.3.28

littlesnack

  • Beginner
  • *
  • Posts: 11
Re: Remove Displayed Name / username field
« Reply #3 on: September 05, 2012, 15:42:14 pm »
@littlesnack,

NOTICE: You should never hack the core template (or the core files in general). Use template overrides, that's what they're there for.

You're right, i will update the post with template overrides. And update my site too. Thanks.

littlesnack

  • Beginner
  • *
  • Posts: 11
Re: Remove Displayed Name / username field
« Reply #4 on: September 05, 2012, 17:11:54 pm »
And if i had to override components\com_virtuemart\controllers\cart.php   ????
I tried with templates/[mytemplate]/html/com_virtuemart/cart.php and templates\[mytemplate]\html\com_virtuemart\controllers\cart.php


ivus

  • Full Member
  • ***
  • Posts: 534
  • - YAY me... proud member of the 500 club...
Re: Remove Displayed Name / username field
« Reply #5 on: September 06, 2012, 03:33:45 am »
That's a controller. They're protected.

You can only override templates and module layouts.

ovcharoff

  • Beginner
  • *
  • Posts: 25
Re: Remove Displayed Name / username field
« Reply #6 on: February 22, 2013, 11:17:21 am »
Thank you, thank you, thank you !

Edit for Virtuemart 2.0.18a

I only added this to the bottom of edit_address_userfields.php in my html template folder:

Code: [Select]
<script type="text/javascript">
  document.getElementById("email_field").setAttribute("onchange", "mail_is_user()");
 
    function mail_is_user(){
var reg_email = document.getElementById("email_field").value
document.getElementById("name_field").value = (reg_email);
document.getElementById("username_field").value = (reg_email);
}

</script>

Then in my template css I added the following:

Code: [Select]
label.name, input#name_field, label.username, input#username_field {
display: none;
}

And it works !

Thank you very much for your simple and genius solution to two of my problems !

Best Regards,

Teodor Ovcharov

naoko15

  • Jr. Member
  • **
  • Posts: 195
Re: Remove Displayed Name / username field
« Reply #7 on: March 27, 2013, 10:02:52 am »
This doesn't work for me. How can i make it work for VM 2.0.2b?

Thanks.

webmaxter

  • Beginner
  • *
  • Posts: 3
Re: Remove Displayed Name / username field
« Reply #8 on: April 04, 2013, 15:01:53 pm »
Yes, this doesn't work for VM 2.20b  :(

I have the same problem. Looks like there are  a lot of changes since 2.18 version. Looking for the solution for 2.20b ... ...

Anybody knows?

glenns

  • Beginner
  • *
  • Posts: 6
Re: Remove Displayed Name / username field
« Reply #9 on: July 09, 2013, 03:58:24 am »
Yes, this doesn't work for VM 2.20b  :(

I have the same problem. Looks like there are  a lot of changes since 2.18 version. Looking for the solution for 2.20b ... ...

Anybody knows?

I too have this problem...the code is totally different in the 2.20 of virtuemart. Can anyone shed some light on how we hide/autofill this ridiculous field "displayed name" on the registration form.

the code is like this now:

<table  class="adminForm user-details">

      <?php
      }

      // Output: Userfields
      ?>
            <tr>
               <td class="key" title="<?php echo $field['description'] ?>" >
                  <label class="<?php echo $field['name'] ?>" for="<?php echo $field['name'] ?>_field">
                     <?php echo $field['title'] . ($field['required'] ? ' *' : '') ?>
                  </label>
               </td>
               <td>
                  <?php echo $field['formcode'] ?>
               </td>
            </tr>

glenns

  • Beginner
  • *
  • Posts: 6
Re: Remove Displayed Name / username field
« Reply #10 on: July 22, 2013, 07:22:48 am »
Ok I think I have found the solution for v2.02 users....you just use the script and css as supplied previously. I only wanted to hide the Displayed Name but leave the Username there....i pasted the below onto line 89 after the </fieldset> in the edit_address_userfields.php file

Code: [Select]
<script type="text/javascript">
  document.getElementById("username_field").setAttribute("onchange", "username_is_user()");
 
    function username_is_user(){
var reg_username = document.getElementById("username_field").value
document.getElementById("name_field").value = (reg_username);
}

</script>

In my instance the label was not it's own css class, it sat amongst a bunch of other css and for whatever reason the label.name override wouldn't work for me, so I had to create a new label class (and delete label from where it previously sat) and then add the subsequent label.name class.

I created the below to suit my situation:

Code: [Select]
label {
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  font-size: 100%;
  vertical-align: baseline;
  background: transparent;
}

label.name, input#name_field {
  display: none;
}

Displayed name is now hidden and automatically fills out with the username

Osearcaigh

  • Beginner
  • *
  • Posts: 19
Re: Remove Displayed Name / username field
« Reply #11 on: September 03, 2013, 15:33:58 pm »
For version 2.0.22b, in order to remove both username and displayed name, make changes to edit_address_userfields.php using overrides as described above.

Change:

Code: [Select]
<tr>
<td class="key" title="<?php echo $field['description'?>" >
<label class="<?php echo $field['name'?>" for="<?php echo $field['name'?>_field">
<?php echo $field['title'] . ($field['required'] ? ' *' ''?>
</label>
</td>
<td>
<?php echo $field['formcode'?>
</td>
</tr>

to:

Code: [Select]
<tr <?php if ($field['name']=="name" or $field['name']=="username") {echo 'style=display:none;';};?>">
<td class="key" title="<?php echo $field['description'?>" >
<label class="<?php echo $field['name'?>" for="<?php echo $field['name'?>_field">
<?php echo $field['title'] . ($field['required'] ? ' *' ''?>
</label>
</td>
<td>
<?php echo $field['formcode'?>
</td>
</tr>

That will hide the username and name fields. Then add the following JavaScript to automatically copy the email into those now hidden fields.


Code: [Select]
<script type="text/javascript">
  document.getElementById("email_field").setAttribute("onchange", "mail_is_user()");
 
    function mail_is_user(){
var reg_email = document.getElementById("email_field").value
document.getElementById("name_field").value = (reg_email);
document.getElementById("username_field").value = (reg_email);
}

</script>




tremer

  • Beginner
  • *
  • Posts: 1
Re: Remove Displayed Name / username field
« Reply #12 on: September 14, 2013, 19:48:34 pm »
Hi all,

VM 2.0.22c
I am using also Onepage Checkout.
No one of the samples above work for me. 

Do you have any idea?

Maxim Pishnyak

  • Virtuemart 2 is quite bugfree now
  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2657
  • Virtuemart 2 is quite bugfree now
    • Virtuemart Ukraine division
Re: Remove Displayed Name / username field
« Reply #13 on: September 16, 2013, 05:26:04 am »
You need to contact developer of OPC. It has slightly different structure then VM.
Virtuemart 2 is quite bugfree now. You can support Community by voting for Project on the JED
http://extensions.joomla.org/extensions/e-commerce/shopping-cart/129/review
Join us in
https://www.facebook.com/virtuemart
https://twitter.com/virtuemart

Marttyn

  • Jr. Member
  • **
  • Posts: 83
Re: Remove Displayed Name / username field
« Reply #14 on: September 18, 2013, 00:54:02 am »
I was having the same problem.
Your solution is GRATE! But the problem is that you javascript IS NOT cross browser, so in some browsers the code will not work, and the user will get stuck, as the JS will not "copy" the content from email_field and "paste" it on the other two (name and user_name), as the form validator is expecting the user to complete every field, but we hide and left empty some textbox.

To fix this we can use jquery that solve this for us, with only this code instead:
Code: [Select]
<script type="text/javascript">
var $j = jQuery.noConflict(); //avoid conflict with other libraries

$j('#username_field').change(function () {             
var reg_user = $j('#username_field').val(); //set username value inside variable
    $j('#name_field').val(reg_user); //assign variable value to name
});
</script>

Note that im leaving user_name visible, and making name = user_name. Make necessary changes to fit your needs.
Also, this code should be AFTER the html table, otherwise it will not work.