How to remove the last name field in registration form?
Magento – Magento 2 – Remove last name from registration form
customermagento2register
Related Solutions
You cannot split the form into 2 columns via the layout xml. The term "columns" has a different meaning it Magento. A column acts like a container for the elements inside it and you need all the fields to be in the same container because they should be wrapped in a form.
But what you can do is to edit the template customer/form/register.phtml
and change the markup to fit your needs. Copy the file from app/design/frontend/base/default/template/customer/form/register.phtml
to your theme app/design/frontend/{package}/{theme}/template/customer/form/register.phtml
keeping the same path and work your magic in the clone.
It's just part of Magento's architecture to use a first name and a last name.
Your question asks why this is the case. Presumably, Magento has added the firstname
and lastname
attributes (along with even an optional middlename
one is defined as default but not displayed) to provide as much flexibility as possible for the merchant. This is a departure from other more established sites, as you noted, but Magento has to cater for a range of possible merchants, and tries to be as non-specific as possible.
However, like all of Magento, nothing is set in stone, and it can be changed, however this is a coding exercise, and as a result can be quite a complicated procedure. To enable this, you'd need to do a few different things. I'll try and detail the steps I'd take below.
1. Add Full Name Attribute
The full name needs to be added as an attribute to a customer. You can create a module to handle this, but essentially, you'll need to run an installer script to install fullname
as an attribute against the customer attribute set.
There are lots of useful tutorials about this around the web. Excellence Magento has a great one (code partially shown below, edited to your requirements)
$setup->addAttribute('customer', 'fullname', array(
'type' => 'text',
'input' => 'text',
'label' => 'Full Name',
'global' => 1,
'visible' => 1,
'required' => 1,
'user_defined' => 1,
'default' => '0',
'visible_on_front' => 1
));
2. Add your new attribute in your templates
You'd now need to go through and add the field for your new attribute to all relevant templates; thereby allowing the user input of it.
You can remove the First Name and Last Name fields in the process, wherever they are applicable.
3. Adjust the firstname and lastname attributes
First Name and Last Name are required attributes in the database, so you won't be able to do much until you remove their required
status from the attributes themselves.
You'll need to write a single-use script to adjust the settings; the code should resemble the following:
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','firstname');
if ($attributeId) {
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attribute->setIsRequired(false)->save();
}
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','lastname');
if ($attributeId) {
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attribute->setIsRequired(false)->save();
}
After that, you should have successfully transferred firstname
and lastname
into a single fullname
field.
If you have any existing customers, you'll be able to write a script that will combine the firstname
and lastname
fields into the fullname
one.
Best Answer
You have to copy file from
And paste to in you theme.
You can find class field-name-lastname in code. delete complete this div for last name.
You have to run below query in your database for set lastname as optional for customer.
Run Command :
php bin/magento cache:clean
Let me know if you have any issue.