News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Remove Displayed Name / username field

Started by littlesnack, September 04, 2012, 17:39:13 PM

Previous topic - Next topic

littlesnack

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


        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 echo ' <tr>' . "\n";
with

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

?>
<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

@littlesnack,

QuoteWarning: 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

Mmmm... very very interesting....

Thx snack!!


Quote from: ivus on September 05, 2012, 00:59:53 AM

QuoteWarning: 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

Quote from: ivus on September 05, 2012, 00:59:53 AM
@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

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

That's a controller. They're protected.

You can only override templates and module layouts.

ovcharoff

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:

<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:

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

This doesn't work for me. How can i make it work for VM 2.0.2b?

Thanks.

webmaxter

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

Quote from: webmaxter 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?

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

#10
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

<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:

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

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:


<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:


<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.



<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

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

You need to contact developer of OPC. It has slightly different structure then VM.
You can support Community by voting for Project on the JED
https://extensions.joomla.org/extension/virtuemart/#reviews
Join us at
https://twitter.com/virtuemart

Marttyn

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:
<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.