Author Topic: "Displayed Name" in Checkout: Can it Auto-Fill with First & Last Name and Hide  (Read 204 times)

bryanearl

  • Beginner
  • *
  • Posts: 33
  • Web Design and SEO / SMO
    • Bryan Earl Web Design
Alright, I have done a lot of reading about this topic but I cannot seem to find this exact info to make this work for me... In checkout, there is a field for "Displayed Name", which I have learned is for the Joomla Core user field "Name" when registering an account. Therefore, I understand that in order to register an account during checkout, SOMETHING needs to be used there.

However, I do NOT want this field to be seen by customers because it is confusing and redundant. Therefore, I would like to hide the field using CSS and auto-fill it with whatever the user inputs for the "First Name" and "Last Name" fields.

I found something close, which looks to be editing this file (templates\xxxxxxxxx\html\com_virtuemart\user\edit_address_userfields.php) and it allows auto-filling the "Displayed Name" field using the "username" data:

Code: [Select]
<?php
if ($addrtype != 'ST') {
?>

<script type="text/javascript">
    document.getElementById("username_field").setAttribute("onchange", "username_is_name_field()");
   
    function username_is_name_field(){
      var reg_fill_name_field = document.getElementById("username_field").value
      document.getElementById("name_field").value = (reg_fill_name_field);
   }
</script>
<?php  ?>

However, I really want it to auto-fill using the "first name" AND "last name" fields instead of username. Can anyone help me with this one?


bryanearl

  • Beginner
  • *
  • Posts: 33
  • Web Design and SEO / SMO
    • Bryan Earl Web Design
UPDATE:

I have managed to make this work on the basic, built-in registration and checkout pages (the URL I provided above) by finding a code snippet from someone else. It does exactly what I wanted, which is to auto-fill the "Displayed Name" field using the First name + Last Name.

Here is the working code, by creating an override of the "edit_address_userfields.php" file:

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("username_field").value = (reg_email);
}

document.getElementById("first_name_field").setAttribute("onchange", "joomla_name_is_vmname()");
document.getElementById("last_name_field").setAttribute("onchange", "joomla_name_is_vmname()");
    function joomla_name_is_vmname(){
var first_name = document.getElementById("first_name_field").value;
var last_name = document.getElementById("last_name_field").value;
document.getElementById("name_field").value = (first_name + ' ' + last_name);
}
</script>

Now, I just need to find a good One-Page Checkout plugin!